@@ -543,14 +543,15 @@ def test_tda_add_sub_index(self):
543
543
544
544
def test_tda_add_dt64_object_array (self , box_df_fail , tz_naive_fixture ):
545
545
# Result should be cast back to DatetimeArray
546
+ box = box_df_fail
546
547
dti = pd .date_range ("2016-01-01" , periods = 3 , tz = tz_naive_fixture )
547
548
dti = dti ._with_freq (None )
548
549
tdi = dti - dti
549
550
550
- obj = tm .box_expected (tdi , box_df_fail )
551
- other = tm .box_expected (dti , box_df_fail )
551
+ obj = tm .box_expected (tdi , box )
552
+ other = tm .box_expected (dti , box )
552
553
553
- warn = PerformanceWarning if box_df_fail is not pd .DataFrame else None
554
+ warn = PerformanceWarning if box is not pd .DataFrame else None
554
555
with tm .assert_produces_warning (warn ):
555
556
result = obj + other .astype (object )
556
557
tm .assert_equal (result , other )
@@ -1195,16 +1196,19 @@ def test_td64arr_sub_td64_array(self, box_with_array):
1195
1196
result = tdarr - tdi
1196
1197
tm .assert_equal (result , expected )
1197
1198
1198
- def test_td64arr_add_sub_tdi (self , box , names ):
1199
+ def test_td64arr_add_sub_tdi (self , box_with_array , names ):
1199
1200
# GH#17250 make sure result dtype is correct
1200
1201
# GH#19043 make sure names are propagated correctly
1202
+ box = box_with_array
1203
+
1201
1204
if box is pd .DataFrame and names [1 ] != names [0 ]:
1202
1205
pytest .skip (
1203
1206
"Name propagation for DataFrame does not behave like "
1204
1207
"it does for Index/Series"
1205
1208
)
1206
1209
1207
1210
tdi = TimedeltaIndex (["0 days" , "1 day" ], name = names [0 ])
1211
+ tdi = np .array (tdi ) if box is tm .to_array else tdi
1208
1212
ser = Series ([Timedelta (hours = 3 ), Timedelta (hours = 4 )], name = names [1 ])
1209
1213
expected = Series (
1210
1214
[Timedelta (hours = 3 ), Timedelta (days = 1 , hours = 4 )], name = names [2 ]
@@ -1299,8 +1303,10 @@ def test_td64arr_sub_timedeltalike(self, two_hours, box_with_array):
1299
1303
# ------------------------------------------------------------------
1300
1304
# __add__/__sub__ with DateOffsets and arrays of DateOffsets
1301
1305
1302
- def test_td64arr_add_offset_index (self , names , box ):
1306
+ def test_td64arr_add_offset_index (self , names , box_with_array ):
1303
1307
# GH#18849, GH#19744
1308
+ box = box_with_array
1309
+
1304
1310
if box is pd .DataFrame and names [1 ] != names [0 ]:
1305
1311
pytest .skip (
1306
1312
"Name propagation for DataFrame does not behave like "
@@ -1309,6 +1315,7 @@ def test_td64arr_add_offset_index(self, names, box):
1309
1315
1310
1316
tdi = TimedeltaIndex (["1 days 00:00:00" , "3 days 04:00:00" ], name = names [0 ])
1311
1317
other = pd .Index ([pd .offsets .Hour (n = 1 ), pd .offsets .Minute (n = - 2 )], name = names [1 ])
1318
+ other = np .array (other ) if box is tm .to_array else other
1312
1319
1313
1320
expected = TimedeltaIndex (
1314
1321
[tdi [n ] + other [n ] for n in range (len (tdi ))], freq = "infer" , name = names [2 ]
@@ -1347,16 +1354,13 @@ def test_td64arr_add_offset_array(self, box_with_array):
1347
1354
res2 = other + tdi
1348
1355
tm .assert_equal (res2 , expected )
1349
1356
1350
- @pytest .mark .parametrize (
1351
- "names" , [(None , None , None ), ("foo" , "bar" , None ), ("foo" , "foo" , "foo" )]
1352
- )
1353
1357
def test_td64arr_sub_offset_index (self , names , box_with_array ):
1354
1358
# GH#18824, GH#19744
1355
1359
box = box_with_array
1356
1360
xbox = box if box is not tm .to_array else pd .Index
1357
1361
exname = names [2 ] if box is not tm .to_array else names [1 ]
1358
1362
1359
- if box is pd .DataFrame and names [1 ] == "bar" :
1363
+ if box is pd .DataFrame and names [1 ] != names [ 0 ] :
1360
1364
pytest .skip (
1361
1365
"Name propagation for DataFrame does not behave like "
1362
1366
"it does for Index/Series"
@@ -1392,9 +1396,6 @@ def test_td64arr_sub_offset_array(self, box_with_array):
1392
1396
res = tdi - other
1393
1397
tm .assert_equal (res , expected )
1394
1398
1395
- @pytest .mark .parametrize (
1396
- "names" , [(None , None , None ), ("foo" , "bar" , None ), ("foo" , "foo" , "foo" )]
1397
- )
1398
1399
def test_td64arr_with_offset_series (self , names , box_df_fail ):
1399
1400
# GH#18849
1400
1401
box = box_df_fail
@@ -2030,9 +2031,13 @@ def test_td64arr_div_numeric_array(self, box_with_array, vector, any_real_dtype)
2030
2031
with pytest .raises (TypeError , match = pattern ):
2031
2032
vector .astype (object ) / tdser
2032
2033
2033
- def test_td64arr_mul_int_series (self , box_df_fail , names ):
2034
+ def test_td64arr_mul_int_series (self , box_with_array , names , request ):
2034
2035
# GH#19042 test for correct name attachment
2035
- box = box_df_fail # broadcasts along wrong axis, but doesn't raise
2036
+ box = box_with_array
2037
+ if box_with_array is pd .DataFrame and names [2 ] is None :
2038
+ reason = "broadcasts along wrong axis, but doesn't raise"
2039
+ request .node .add_marker (pytest .mark .xfail (reason = reason ))
2040
+
2036
2041
exname = names [2 ] if box is not tm .to_array else names [1 ]
2037
2042
2038
2043
tdi = TimedeltaIndex (
@@ -2056,7 +2061,10 @@ def test_td64arr_mul_int_series(self, box_df_fail, names):
2056
2061
2057
2062
# The direct operation tdi * ser still needs to be fixed.
2058
2063
result = ser .__rmul__ (tdi )
2059
- tm .assert_equal (result , expected )
2064
+ if box is pd .DataFrame :
2065
+ assert result is NotImplemented
2066
+ else :
2067
+ tm .assert_equal (result , expected )
2060
2068
2061
2069
# TODO: Should we be parametrizing over types for `ser` too?
2062
2070
def test_float_series_rdiv_td64arr (self , box_with_array , names ):
0 commit comments