43
43
from pandas .tests .arithmetic .common import (
44
44
assert_invalid_addsub_type ,
45
45
assert_invalid_comparison ,
46
+ get_expected_box ,
46
47
get_upcast_box ,
47
48
)
48
49
@@ -59,9 +60,7 @@ def test_compare_zerodim(self, tz_naive_fixture, box_with_array):
59
60
# Test comparison with zero-dimensional array is unboxed
60
61
tz = tz_naive_fixture
61
62
box = box_with_array
62
- xbox = (
63
- box_with_array if box_with_array not in [pd .Index , pd .array ] else np .ndarray
64
- )
63
+ xbox = get_expected_box (box )
65
64
dti = date_range ("20130101" , periods = 3 , tz = tz )
66
65
67
66
other = np .array (dti .to_numpy ()[0 ])
@@ -148,7 +147,7 @@ def test_dt64arr_nat_comparison(self, tz_naive_fixture, box_with_array):
148
147
# GH#22242, GH#22163 DataFrame considered NaT == ts incorrectly
149
148
tz = tz_naive_fixture
150
149
box = box_with_array
151
- xbox = box if box not in [ pd . Index , pd . array ] else np . ndarray
150
+ xbox = get_expected_box ( box )
152
151
153
152
ts = Timestamp .now (tz )
154
153
ser = Series ([ts , NaT ])
@@ -245,7 +244,7 @@ def test_nat_comparisons_scalar(self, dtype, data, box_with_array):
245
244
# on older numpys (since they check object identity)
246
245
return
247
246
248
- xbox = box if box not in [ pd . Index , pd . array ] else np . ndarray
247
+ xbox = get_expected_box ( box )
249
248
250
249
left = Series (data , dtype = dtype )
251
250
left = tm .box_expected (left , box )
@@ -324,9 +323,7 @@ def test_timestamp_compare_series(self, left, right):
324
323
325
324
def test_dt64arr_timestamp_equality (self , box_with_array ):
326
325
# GH#11034
327
- xbox = (
328
- box_with_array if box_with_array not in [pd .Index , pd .array ] else np .ndarray
329
- )
326
+ xbox = get_expected_box (box_with_array )
330
327
331
328
ser = Series ([Timestamp ("2000-01-29 01:59:00" ), Timestamp ("2000-01-30" ), NaT ])
332
329
ser = tm .box_expected (ser , box_with_array )
@@ -424,9 +421,7 @@ def test_dti_cmp_nat(self, dtype, box_with_array):
424
421
# on older numpys (since they check object identity)
425
422
return
426
423
427
- xbox = (
428
- box_with_array if box_with_array not in [pd .Index , pd .array ] else np .ndarray
429
- )
424
+ xbox = get_expected_box (box_with_array )
430
425
431
426
left = DatetimeIndex ([Timestamp ("2011-01-01" ), NaT , Timestamp ("2011-01-03" )])
432
427
right = DatetimeIndex ([NaT , NaT , Timestamp ("2011-01-03" )])
@@ -662,7 +657,7 @@ def test_scalar_comparison_tzawareness(
662
657
box = box_with_array
663
658
tz = tz_aware_fixture
664
659
dti = date_range ("2016-01-01" , periods = 2 , tz = tz )
665
- xbox = box if box not in [ pd . Index , pd . array ] else np . ndarray
660
+ xbox = get_expected_box ( box )
666
661
667
662
dtarr = tm .box_expected (dti , box_with_array )
668
663
if op in [operator .eq , operator .ne ]:
@@ -2283,7 +2278,7 @@ def test_sub_dti_dti(self):
2283
2278
# cleanup, box-parametrization, and de-duplication
2284
2279
2285
2280
@pytest .mark .parametrize ("op" , [operator .add , operator .sub ])
2286
- def test_timedelta64_equal_timedelta_supported_ops (self , op ):
2281
+ def test_timedelta64_equal_timedelta_supported_ops (self , op , box_with_array ):
2287
2282
ser = Series (
2288
2283
[
2289
2284
Timestamp ("20130301" ),
@@ -2292,6 +2287,7 @@ def test_timedelta64_equal_timedelta_supported_ops(self, op):
2292
2287
Timestamp ("20130228 21:00:00" ),
2293
2288
]
2294
2289
)
2290
+ obj = box_with_array (ser )
2295
2291
2296
2292
intervals = ["D" , "h" , "m" , "s" , "us" ]
2297
2293
@@ -2302,10 +2298,10 @@ def timedelta64(*args):
2302
2298
for d , h , m , s , us in product (* ([range (2 )] * 5 )):
2303
2299
nptd = timedelta64 (d , h , m , s , us )
2304
2300
pytd = timedelta (days = d , hours = h , minutes = m , seconds = s , microseconds = us )
2305
- lhs = op (ser , nptd )
2306
- rhs = op (ser , pytd )
2301
+ lhs = op (obj , nptd )
2302
+ rhs = op (obj , pytd )
2307
2303
2308
- tm .assert_series_equal (lhs , rhs )
2304
+ tm .assert_equal (lhs , rhs )
2309
2305
2310
2306
def test_ops_nat_mixed_datetime64_timedelta64 (self ):
2311
2307
# GH#11349
0 commit comments