Skip to content

Commit d482210

Browse files
replaced test_data fixture with more granular fixtures in pandas/tests/series/indexing/test_alter_index.py
1 parent a720d17 commit d482210

File tree

1 file changed

+58
-57
lines changed

1 file changed

+58
-57
lines changed

pandas/tests/series/indexing/test_alter_index.py

Lines changed: 58 additions & 57 deletions
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

0 commit comments

Comments
 (0)