Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST: Fixturize series/test_missing.py #22973

Merged
merged 2 commits into from
Oct 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions pandas/tests/series/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import pandas.util.testing as tm
import pandas.util._test_decorators as td

from .common import TestData

try:
import scipy
_is_scipy_ge_0190 = (LooseVersion(scipy.__version__) >=
Expand Down Expand Up @@ -52,7 +50,7 @@ def _simple_ts(start, end, freq='D'):
return Series(np.random.randn(len(rng)), index=rng)


class TestSeriesMissingData(TestData):
class TestSeriesMissingData():

def test_remove_na_deprecation(self):
# see gh-16971
Expand Down Expand Up @@ -489,7 +487,7 @@ def test_isnull_for_inf_deprecated(self):
tm.assert_series_equal(r, e)
tm.assert_series_equal(dr, de)

def test_fillna(self):
def test_fillna(self, datetime_series):
ts = Series([0., 1., 2., 3., 4.], index=tm.makeDateIndex(5))

tm.assert_series_equal(ts, ts.fillna(method='ffill'))
Expand All @@ -506,7 +504,8 @@ def test_fillna(self):
tm.assert_series_equal(ts.fillna(value=5), exp)

pytest.raises(ValueError, ts.fillna)
pytest.raises(ValueError, self.ts.fillna, value=0, method='ffill')
pytest.raises(ValueError, datetime_series.fillna, value=0,
method='ffill')

# GH 5703
s1 = Series([np.nan])
Expand Down Expand Up @@ -576,9 +575,9 @@ def test_fillna_inplace(self):
expected = x.fillna(value=0)
assert_series_equal(y, expected)

def test_fillna_invalid_method(self):
def test_fillna_invalid_method(self, datetime_series):
try:
self.ts.fillna(method='ffil')
datetime_series.fillna(method='ffil')
except ValueError as inst:
assert 'ffil' in str(inst)

Expand Down Expand Up @@ -632,8 +631,8 @@ def test_timedelta64_nan(self):

# def test_logical_range_select(self):
# np.random.seed(12345)
# selector = -0.5 <= self.ts <= 0.5
# expected = (self.ts >= -0.5) & (self.ts <= 0.5)
# selector = -0.5 <= datetime_series <= 0.5
# expected = (datetime_series >= -0.5) & (datetime_series <= 0.5)
# assert_series_equal(selector, expected)

def test_dropna_empty(self):
Expand Down Expand Up @@ -688,8 +687,8 @@ def test_dropna_intervals(self):
expected = s.iloc[1:]
assert_series_equal(result, expected)

def test_valid(self):
ts = self.ts.copy()
def test_valid(self, datetime_series):
ts = datetime_series.copy()
ts[::2] = np.NaN

result = ts.dropna()
Expand Down Expand Up @@ -734,12 +733,12 @@ def test_pad_require_monotonicity(self):

pytest.raises(ValueError, rng2.get_indexer, rng, method='pad')

def test_dropna_preserve_name(self):
self.ts[:5] = np.nan
result = self.ts.dropna()
assert result.name == self.ts.name
name = self.ts.name
ts = self.ts.copy()
def test_dropna_preserve_name(self, datetime_series):
datetime_series[:5] = np.nan
result = datetime_series.dropna()
assert result.name == datetime_series.name
name = datetime_series.name
ts = datetime_series.copy()
ts.dropna(inplace=True)
assert ts.name == name

Expand Down Expand Up @@ -825,19 +824,20 @@ def test_series_pad_backfill_limit(self):
assert_series_equal(result, expected)


class TestSeriesInterpolateData(TestData):
class TestSeriesInterpolateData():

def test_interpolate(self):
ts = Series(np.arange(len(self.ts), dtype=float), self.ts.index)
def test_interpolate(self, datetime_series, string_series):
ts = Series(np.arange(len(datetime_series), dtype=float),
datetime_series.index)

ts_copy = ts.copy()
ts_copy[5:10] = np.NaN

linear_interp = ts_copy.interpolate(method='linear')
tm.assert_series_equal(linear_interp, ts)

ord_ts = Series([d.toordinal() for d in self.ts.index],
index=self.ts.index).astype(float)
ord_ts = Series([d.toordinal() for d in datetime_series.index],
index=datetime_series.index).astype(float)

ord_ts_copy = ord_ts.copy()
ord_ts_copy[5:10] = np.NaN
Expand All @@ -847,7 +847,7 @@ def test_interpolate(self):

# try time interpolation on a non-TimeSeries
# Only raises ValueError if there are NaNs.
non_ts = self.series.copy()
non_ts = string_series.copy()
non_ts[0] = np.NaN
pytest.raises(ValueError, non_ts.interpolate, method='time')

Expand Down