Skip to content

Commit 6caba07

Browse files
SaturnFromTitanjreback
authored andcommitted
Remove TestData in series tests indexing (#29220)
1 parent 97d2399 commit 6caba07

File tree

8 files changed

+206
-247
lines changed

8 files changed

+206
-247
lines changed

pandas/tests/indexes/datetimes/test_date_range.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import pandas as pd
1616
from pandas import DatetimeIndex, Timestamp, bdate_range, date_range, offsets
17-
from pandas.tests.series.common import TestData
1817
import pandas.util.testing as tm
1918

2019
from pandas.tseries.offsets import (
@@ -82,7 +81,7 @@ def test_date_range_timestamp_equiv_preserve_frequency(self):
8281
assert timestamp_instance == ts
8382

8483

85-
class TestDateRanges(TestData):
84+
class TestDateRanges:
8685
def test_date_range_nat(self):
8786
# GH#11587
8887
msg = "Neither `start` nor `end` can be NaT"

pandas/tests/series/common.py

-30
This file was deleted.

pandas/tests/series/indexing/conftest.py

-8
This file was deleted.

pandas/tests/series/indexing/test_alter_index.py

+58-57
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
],
2020
)
2121
@pytest.mark.parametrize("fill", [None, -1])
22-
def test_align(test_data, first_slice, second_slice, join_type, fill):
23-
a = test_data.ts[slice(*first_slice)]
24-
b = test_data.ts[slice(*second_slice)]
22+
def test_align(datetime_series, first_slice, second_slice, join_type, fill):
23+
a = datetime_series[slice(*first_slice)]
24+
b = datetime_series[slice(*second_slice)]
2525

2626
aa, ab = a.align(b, join=join_type, fill_value=fill)
2727

@@ -61,10 +61,10 @@ def test_align(test_data, first_slice, second_slice, join_type, fill):
6161
@pytest.mark.parametrize("method", ["pad", "bfill"])
6262
@pytest.mark.parametrize("limit", [None, 1])
6363
def test_align_fill_method(
64-
test_data, first_slice, second_slice, join_type, method, limit
64+
datetime_series, first_slice, second_slice, join_type, method, limit
6565
):
66-
a = test_data.ts[slice(*first_slice)]
67-
b = test_data.ts[slice(*second_slice)]
66+
a = datetime_series[slice(*first_slice)]
67+
b = datetime_series[slice(*second_slice)]
6868

6969
aa, ab = a.align(b, join=join_type, method=method, limit=limit)
7070

@@ -79,44 +79,44 @@ def test_align_fill_method(
7979
assert_series_equal(ab, eb)
8080

8181

82-
def test_align_nocopy(test_data):
83-
b = test_data.ts[:5].copy()
82+
def test_align_nocopy(datetime_series):
83+
b = datetime_series[:5].copy()
8484

8585
# do copy
86-
a = test_data.ts.copy()
86+
a = datetime_series.copy()
8787
ra, _ = a.align(b, join="left")
8888
ra[:5] = 5
8989
assert not (a[:5] == 5).any()
9090

9191
# do not copy
92-
a = test_data.ts.copy()
92+
a = datetime_series.copy()
9393
ra, _ = a.align(b, join="left", copy=False)
9494
ra[:5] = 5
9595
assert (a[:5] == 5).all()
9696

9797
# do copy
98-
a = test_data.ts.copy()
99-
b = test_data.ts[:5].copy()
98+
a = datetime_series.copy()
99+
b = datetime_series[:5].copy()
100100
_, rb = a.align(b, join="right")
101101
rb[:3] = 5
102102
assert not (b[:3] == 5).any()
103103

104104
# do not copy
105-
a = test_data.ts.copy()
106-
b = test_data.ts[:5].copy()
105+
a = datetime_series.copy()
106+
b = datetime_series[:5].copy()
107107
_, rb = a.align(b, join="right", copy=False)
108108
rb[:2] = 5
109109
assert (b[:2] == 5).all()
110110

111111

112-
def test_align_same_index(test_data):
113-
a, b = test_data.ts.align(test_data.ts, copy=False)
114-
assert a.index is test_data.ts.index
115-
assert b.index is test_data.ts.index
112+
def test_align_same_index(datetime_series):
113+
a, b = datetime_series.align(datetime_series, copy=False)
114+
assert a.index is datetime_series.index
115+
assert b.index is datetime_series.index
116116

117-
a, b = test_data.ts.align(test_data.ts, copy=True)
118-
assert a.index is not test_data.ts.index
119-
assert b.index is not test_data.ts.index
117+
a, b = datetime_series.align(datetime_series, copy=True)
118+
assert a.index is not datetime_series.index
119+
assert b.index is not datetime_series.index
120120

121121

122122
def test_align_multiindex():
@@ -154,43 +154,43 @@ def test_align_multiindex():
154154
tm.assert_series_equal(expr, res2l)
155155

156156

157-
def test_reindex(test_data):
158-
identity = test_data.series.reindex(test_data.series.index)
157+
def test_reindex(datetime_series, string_series):
158+
identity = string_series.reindex(string_series.index)
159159

160160
# __array_interface__ is not defined for older numpies
161161
# and on some pythons
162162
try:
163-
assert np.may_share_memory(test_data.series.index, identity.index)
163+
assert np.may_share_memory(string_series.index, identity.index)
164164
except AttributeError:
165165
pass
166166

167-
assert identity.index.is_(test_data.series.index)
168-
assert identity.index.identical(test_data.series.index)
167+
assert identity.index.is_(string_series.index)
168+
assert identity.index.identical(string_series.index)
169169

170-
subIndex = test_data.series.index[10:20]
171-
subSeries = test_data.series.reindex(subIndex)
170+
subIndex = string_series.index[10:20]
171+
subSeries = string_series.reindex(subIndex)
172172

173173
for idx, val in subSeries.items():
174-
assert val == test_data.series[idx]
174+
assert val == string_series[idx]
175175

176-
subIndex2 = test_data.ts.index[10:20]
177-
subTS = test_data.ts.reindex(subIndex2)
176+
subIndex2 = datetime_series.index[10:20]
177+
subTS = datetime_series.reindex(subIndex2)
178178

179179
for idx, val in subTS.items():
180-
assert val == test_data.ts[idx]
181-
stuffSeries = test_data.ts.reindex(subIndex)
180+
assert val == datetime_series[idx]
181+
stuffSeries = datetime_series.reindex(subIndex)
182182

183183
assert np.isnan(stuffSeries).all()
184184

185185
# This is extremely important for the Cython code to not screw up
186-
nonContigIndex = test_data.ts.index[::2]
187-
subNonContig = test_data.ts.reindex(nonContigIndex)
186+
nonContigIndex = datetime_series.index[::2]
187+
subNonContig = datetime_series.reindex(nonContigIndex)
188188
for idx, val in subNonContig.items():
189-
assert val == test_data.ts[idx]
189+
assert val == datetime_series[idx]
190190

191191
# return a copy the same index here
192-
result = test_data.ts.reindex()
193-
assert not (result is test_data.ts)
192+
result = datetime_series.reindex()
193+
assert not (result is datetime_series)
194194

195195

196196
def test_reindex_nan():
@@ -229,25 +229,26 @@ def test_reindex_with_datetimes():
229229
tm.assert_series_equal(result, expected)
230230

231231

232-
def test_reindex_corner(test_data):
232+
def test_reindex_corner(datetime_series):
233233
# (don't forget to fix this) I think it's fixed
234-
test_data.empty.reindex(test_data.ts.index, method="pad") # it works
234+
empty = Series()
235+
empty.reindex(datetime_series.index, method="pad") # it works
235236

236237
# corner case: pad empty series
237-
reindexed = test_data.empty.reindex(test_data.ts.index, method="pad")
238+
reindexed = empty.reindex(datetime_series.index, method="pad")
238239

239240
# pass non-Index
240-
reindexed = test_data.ts.reindex(list(test_data.ts.index))
241-
assert_series_equal(test_data.ts, reindexed)
241+
reindexed = datetime_series.reindex(list(datetime_series.index))
242+
assert_series_equal(datetime_series, reindexed)
242243

243244
# bad fill method
244-
ts = test_data.ts[::2]
245+
ts = datetime_series[::2]
245246
msg = (
246247
r"Invalid fill method\. Expecting pad \(ffill\), backfill"
247248
r" \(bfill\) or nearest\. Got foo"
248249
)
249250
with pytest.raises(ValueError, match=msg):
250-
ts.reindex(test_data.ts.index, method="foo")
251+
ts.reindex(datetime_series.index, method="foo")
251252

252253

253254
def test_reindex_pad():
@@ -319,12 +320,12 @@ def test_reindex_backfill():
319320
pass
320321

321322

322-
def test_reindex_int(test_data):
323-
ts = test_data.ts[::2]
323+
def test_reindex_int(datetime_series):
324+
ts = datetime_series[::2]
324325
int_ts = Series(np.zeros(len(ts), dtype=int), index=ts.index)
325326

326327
# this should work fine
327-
reindexed_int = int_ts.reindex(test_data.ts.index)
328+
reindexed_int = int_ts.reindex(datetime_series.index)
328329

329330
# if NaNs introduced
330331
assert reindexed_int.dtype == np.float_
@@ -334,13 +335,13 @@ def test_reindex_int(test_data):
334335
assert reindexed_int.dtype == np.int_
335336

336337

337-
def test_reindex_bool(test_data):
338+
def test_reindex_bool(datetime_series):
338339
# A series other than float, int, string, or object
339-
ts = test_data.ts[::2]
340+
ts = datetime_series[::2]
340341
bool_ts = Series(np.zeros(len(ts), dtype=bool), index=ts.index)
341342

342343
# this should work fine
343-
reindexed_bool = bool_ts.reindex(test_data.ts.index)
344+
reindexed_bool = bool_ts.reindex(datetime_series.index)
344345

345346
# if NaNs introduced
346347
assert reindexed_bool.dtype == np.object_
@@ -350,11 +351,11 @@ def test_reindex_bool(test_data):
350351
assert reindexed_bool.dtype == np.bool_
351352

352353

353-
def test_reindex_bool_pad(test_data):
354+
def test_reindex_bool_pad(datetime_series):
354355
# fail
355-
ts = test_data.ts[5:]
356+
ts = datetime_series[5:]
356357
bool_ts = Series(np.zeros(len(ts), dtype=bool), index=ts.index)
357-
filled_bool = bool_ts.reindex(test_data.ts.index, method="pad")
358+
filled_bool = bool_ts.reindex(datetime_series.index, method="pad")
358359
assert isna(filled_bool[:5]).all()
359360

360361

@@ -382,10 +383,10 @@ def test_reindex_categorical():
382383
tm.assert_series_equal(result, expected)
383384

384385

385-
def test_reindex_like(test_data):
386-
other = test_data.ts[::2]
386+
def test_reindex_like(datetime_series):
387+
other = datetime_series[::2]
387388
assert_series_equal(
388-
test_data.ts.reindex(other.index), test_data.ts.reindex_like(other)
389+
datetime_series.reindex(other.index), datetime_series.reindex_like(other)
389390
)
390391

391392
# GH 7179

pandas/tests/series/indexing/test_boolean.py

+21-21
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
from pandas.tseries.offsets import BDay
1313

1414

15-
def test_getitem_boolean(test_data):
16-
s = test_data.series
15+
def test_getitem_boolean(string_series):
16+
s = string_series
1717
mask = s > s.median()
1818

1919
# passing list is OK
@@ -55,10 +55,10 @@ def test_getitem_boolean_empty():
5555
s[Series([True], dtype=bool)]
5656

5757

58-
def test_getitem_boolean_object(test_data):
58+
def test_getitem_boolean_object(string_series):
5959
# using column from DataFrame
6060

61-
s = test_data.series
61+
s = string_series
6262
mask = s > s.median()
6363
omask = mask.astype(object)
6464

@@ -83,8 +83,8 @@ def test_getitem_boolean_object(test_data):
8383
s[omask] = 5
8484

8585

86-
def test_getitem_setitem_boolean_corner(test_data):
87-
ts = test_data.ts
86+
def test_getitem_setitem_boolean_corner(datetime_series):
87+
ts = datetime_series
8888
mask_shifted = ts.shift(1, freq=BDay()) > ts.median()
8989

9090
# these used to raise...??
@@ -104,38 +104,38 @@ def test_getitem_setitem_boolean_corner(test_data):
104104
ts.loc[mask_shifted] = 1
105105

106106

107-
def test_setitem_boolean(test_data):
108-
mask = test_data.series > test_data.series.median()
107+
def test_setitem_boolean(string_series):
108+
mask = string_series > string_series.median()
109109

110110
# similar indexed series
111-
result = test_data.series.copy()
112-
result[mask] = test_data.series * 2
113-
expected = test_data.series * 2
111+
result = string_series.copy()
112+
result[mask] = string_series * 2
113+
expected = string_series * 2
114114
assert_series_equal(result[mask], expected[mask])
115115

116116
# needs alignment
117-
result = test_data.series.copy()
118-
result[mask] = (test_data.series * 2)[0:5]
119-
expected = (test_data.series * 2)[0:5].reindex_like(test_data.series)
120-
expected[-mask] = test_data.series[mask]
117+
result = string_series.copy()
118+
result[mask] = (string_series * 2)[0:5]
119+
expected = (string_series * 2)[0:5].reindex_like(string_series)
120+
expected[-mask] = string_series[mask]
121121
assert_series_equal(result[mask], expected[mask])
122122

123123

124-
def test_get_set_boolean_different_order(test_data):
125-
ordered = test_data.series.sort_values()
124+
def test_get_set_boolean_different_order(string_series):
125+
ordered = string_series.sort_values()
126126

127127
# setting
128-
copy = test_data.series.copy()
128+
copy = string_series.copy()
129129
copy[ordered > 0] = 0
130130

131-
expected = test_data.series.copy()
131+
expected = string_series.copy()
132132
expected[expected > 0] = 0
133133

134134
assert_series_equal(copy, expected)
135135

136136
# getting
137-
sel = test_data.series[ordered > 0]
138-
exp = test_data.series[test_data.series > 0]
137+
sel = string_series[ordered > 0]
138+
exp = string_series[string_series > 0]
139139
assert_series_equal(sel, exp)
140140

141141

0 commit comments

Comments
 (0)