@@ -865,7 +865,7 @@ def test_dt64arr_add_sub_td64ndarray(self, tz_naive_fixture, box_with_array):
865
865
tdi = pd .TimedeltaIndex (["-1 Day" , "-1 Day" , "-1 Day" ])
866
866
tdarr = tdi .values
867
867
868
- expected = pd .date_range ("2015-12-31" , periods = 3 , tz = tz )
868
+ expected = pd .date_range ("2015-12-31" , "2016-01-02" , periods = 3 , tz = tz )
869
869
870
870
dtarr = tm .box_expected (dti , box_with_array )
871
871
expected = tm .box_expected (expected , box_with_array )
@@ -875,7 +875,7 @@ def test_dt64arr_add_sub_td64ndarray(self, tz_naive_fixture, box_with_array):
875
875
result = tdarr + dtarr
876
876
tm .assert_equal (result , expected )
877
877
878
- expected = pd .date_range ("2016-01-02" , periods = 3 , tz = tz )
878
+ expected = pd .date_range ("2016-01-02" , "2016-01-04" , periods = 3 , tz = tz )
879
879
expected = tm .box_expected (expected , box_with_array )
880
880
881
881
result = dtarr - tdarr
@@ -1385,13 +1385,13 @@ def test_dt64arr_add_sub_DateOffset(self, box_with_array):
1385
1385
s = tm .box_expected (s , box_with_array )
1386
1386
result = s + pd .DateOffset (years = 1 )
1387
1387
result2 = pd .DateOffset (years = 1 ) + s
1388
- exp = date_range ("2001-01-01" , "2001-01-31" , name = "a" )
1388
+ exp = date_range ("2001-01-01" , "2001-01-31" , name = "a" ). _with_freq ( None )
1389
1389
exp = tm .box_expected (exp , box_with_array )
1390
1390
tm .assert_equal (result , exp )
1391
1391
tm .assert_equal (result2 , exp )
1392
1392
1393
1393
result = s - pd .DateOffset (years = 1 )
1394
- exp = date_range ("1999-01-01" , "1999-01-31" , name = "a" )
1394
+ exp = date_range ("1999-01-01" , "1999-01-31" , name = "a" ). _with_freq ( None )
1395
1395
exp = tm .box_expected (exp , box_with_array )
1396
1396
tm .assert_equal (result , exp )
1397
1397
@@ -1553,7 +1553,7 @@ def test_dti_add_sub_nonzero_mth_offset(
1553
1553
mth = getattr (date , op )
1554
1554
result = mth (offset )
1555
1555
1556
- expected = pd .DatetimeIndex (exp , tz = tz , freq = exp_freq )
1556
+ expected = pd .DatetimeIndex (exp , tz = tz )
1557
1557
expected = tm .box_expected (expected , box_with_array , False )
1558
1558
tm .assert_equal (result , expected )
1559
1559
@@ -2344,29 +2344,29 @@ def test_ufunc_coercions(self):
2344
2344
assert result .freq == "2D"
2345
2345
2346
2346
exp = date_range ("2010-12-31" , periods = 3 , freq = "2D" , name = "x" )
2347
+
2347
2348
for result in [idx - delta , np .subtract (idx , delta )]:
2348
2349
assert isinstance (result , DatetimeIndex )
2349
2350
tm .assert_index_equal (result , exp )
2350
2351
assert result .freq == "2D"
2351
2352
2353
+ # When adding/subtracting an ndarray (which has no .freq), the result
2354
+ # does not infer freq
2355
+ idx = idx ._with_freq (None )
2352
2356
delta = np .array (
2353
2357
[np .timedelta64 (1 , "D" ), np .timedelta64 (2 , "D" ), np .timedelta64 (3 , "D" )]
2354
2358
)
2355
- exp = DatetimeIndex (
2356
- ["2011-01-02" , "2011-01-05" , "2011-01-08" ], freq = "3D" , name = "x"
2357
- )
2359
+ exp = DatetimeIndex (["2011-01-02" , "2011-01-05" , "2011-01-08" ], name = "x" )
2360
+
2358
2361
for result in [idx + delta , np .add (idx , delta )]:
2359
- assert isinstance (result , DatetimeIndex )
2360
2362
tm .assert_index_equal (result , exp )
2361
- assert result .freq == "3D"
2363
+ assert result .freq == exp . freq
2362
2364
2363
- exp = DatetimeIndex (
2364
- ["2010-12-31" , "2011-01-01" , "2011-01-02" ], freq = "D" , name = "x"
2365
- )
2365
+ exp = DatetimeIndex (["2010-12-31" , "2011-01-01" , "2011-01-02" ], name = "x" )
2366
2366
for result in [idx - delta , np .subtract (idx , delta )]:
2367
2367
assert isinstance (result , DatetimeIndex )
2368
2368
tm .assert_index_equal (result , exp )
2369
- assert result .freq == "D"
2369
+ assert result .freq == exp . freq
2370
2370
2371
2371
@pytest .mark .parametrize (
2372
2372
"names" , [("foo" , None , None ), ("baz" , "bar" , None ), ("bar" , "bar" , "bar" )]
0 commit comments