19
19
],
20
20
)
21
21
@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 )]
25
25
26
26
aa , ab = a .align (b , join = join_type , fill_value = fill )
27
27
@@ -61,10 +61,10 @@ def test_align(test_data, first_slice, second_slice, join_type, fill):
61
61
@pytest .mark .parametrize ("method" , ["pad" , "bfill" ])
62
62
@pytest .mark .parametrize ("limit" , [None , 1 ])
63
63
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
65
65
):
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 )]
68
68
69
69
aa , ab = a .align (b , join = join_type , method = method , limit = limit )
70
70
@@ -79,44 +79,44 @@ def test_align_fill_method(
79
79
assert_series_equal (ab , eb )
80
80
81
81
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 ()
84
84
85
85
# do copy
86
- a = test_data . ts .copy ()
86
+ a = datetime_series .copy ()
87
87
ra , _ = a .align (b , join = "left" )
88
88
ra [:5 ] = 5
89
89
assert not (a [:5 ] == 5 ).any ()
90
90
91
91
# do not copy
92
- a = test_data . ts .copy ()
92
+ a = datetime_series .copy ()
93
93
ra , _ = a .align (b , join = "left" , copy = False )
94
94
ra [:5 ] = 5
95
95
assert (a [:5 ] == 5 ).all ()
96
96
97
97
# 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 ()
100
100
_ , rb = a .align (b , join = "right" )
101
101
rb [:3 ] = 5
102
102
assert not (b [:3 ] == 5 ).any ()
103
103
104
104
# 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 ()
107
107
_ , rb = a .align (b , join = "right" , copy = False )
108
108
rb [:2 ] = 5
109
109
assert (b [:2 ] == 5 ).all ()
110
110
111
111
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
116
116
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
120
120
121
121
122
122
def test_align_multiindex ():
@@ -154,43 +154,43 @@ def test_align_multiindex():
154
154
tm .assert_series_equal (expr , res2l )
155
155
156
156
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 )
159
159
160
160
# __array_interface__ is not defined for older numpies
161
161
# and on some pythons
162
162
try :
163
- assert np .may_share_memory (test_data . series .index , identity .index )
163
+ assert np .may_share_memory (string_series .index , identity .index )
164
164
except AttributeError :
165
165
pass
166
166
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 )
169
169
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 )
172
172
173
173
for idx , val in subSeries .items ():
174
- assert val == test_data . series [idx ]
174
+ assert val == string_series [idx ]
175
175
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 )
178
178
179
179
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 )
182
182
183
183
assert np .isnan (stuffSeries ).all ()
184
184
185
185
# 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 )
188
188
for idx , val in subNonContig .items ():
189
- assert val == test_data . ts [idx ]
189
+ assert val == datetime_series [idx ]
190
190
191
191
# 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 )
194
194
195
195
196
196
def test_reindex_nan ():
@@ -229,25 +229,26 @@ def test_reindex_with_datetimes():
229
229
tm .assert_series_equal (result , expected )
230
230
231
231
232
- def test_reindex_corner (test_data ):
232
+ def test_reindex_corner (datetime_series ):
233
233
# (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
235
236
236
237
# 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" )
238
239
239
240
# 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 )
242
243
243
244
# bad fill method
244
- ts = test_data . ts [::2 ]
245
+ ts = datetime_series [::2 ]
245
246
msg = (
246
247
r"Invalid fill method\. Expecting pad \(ffill\), backfill"
247
248
r" \(bfill\) or nearest\. Got foo"
248
249
)
249
250
with pytest .raises (ValueError , match = msg ):
250
- ts .reindex (test_data . ts .index , method = "foo" )
251
+ ts .reindex (datetime_series .index , method = "foo" )
251
252
252
253
253
254
def test_reindex_pad ():
@@ -319,12 +320,12 @@ def test_reindex_backfill():
319
320
pass
320
321
321
322
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 ]
324
325
int_ts = Series (np .zeros (len (ts ), dtype = int ), index = ts .index )
325
326
326
327
# this should work fine
327
- reindexed_int = int_ts .reindex (test_data . ts .index )
328
+ reindexed_int = int_ts .reindex (datetime_series .index )
328
329
329
330
# if NaNs introduced
330
331
assert reindexed_int .dtype == np .float_
@@ -334,13 +335,13 @@ def test_reindex_int(test_data):
334
335
assert reindexed_int .dtype == np .int_
335
336
336
337
337
- def test_reindex_bool (test_data ):
338
+ def test_reindex_bool (datetime_series ):
338
339
# A series other than float, int, string, or object
339
- ts = test_data . ts [::2 ]
340
+ ts = datetime_series [::2 ]
340
341
bool_ts = Series (np .zeros (len (ts ), dtype = bool ), index = ts .index )
341
342
342
343
# this should work fine
343
- reindexed_bool = bool_ts .reindex (test_data . ts .index )
344
+ reindexed_bool = bool_ts .reindex (datetime_series .index )
344
345
345
346
# if NaNs introduced
346
347
assert reindexed_bool .dtype == np .object_
@@ -350,11 +351,11 @@ def test_reindex_bool(test_data):
350
351
assert reindexed_bool .dtype == np .bool_
351
352
352
353
353
- def test_reindex_bool_pad (test_data ):
354
+ def test_reindex_bool_pad (datetime_series ):
354
355
# fail
355
- ts = test_data . ts [5 :]
356
+ ts = datetime_series [5 :]
356
357
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" )
358
359
assert isna (filled_bool [:5 ]).all ()
359
360
360
361
@@ -382,10 +383,10 @@ def test_reindex_categorical():
382
383
tm .assert_series_equal (result , expected )
383
384
384
385
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 ]
387
388
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 )
389
390
)
390
391
391
392
# GH 7179
0 commit comments