@@ -1438,64 +1438,41 @@ def test_dt64arr_add_sub_DateOffset(self, box_with_array):
1438
1438
tm .assert_equal (result , exp )
1439
1439
tm .assert_equal (result2 , exp )
1440
1440
1441
- # TODO: __sub__, __rsub__
1442
- def test_dt64arr_add_mixed_offset_array (self , box_with_array ):
1443
- # GH#10699
1444
- # array of offsets
1445
- s = DatetimeIndex ([Timestamp ("2000-1-1" ), Timestamp ("2000-2-1" )])
1446
- s = tm .box_expected (s , box_with_array )
1447
-
1448
- warn = None if box_with_array is pd .DataFrame else PerformanceWarning
1449
- with tm .assert_produces_warning (warn ):
1450
- other = pd .Index ([pd .offsets .DateOffset (years = 1 ), pd .offsets .MonthEnd ()])
1451
- other = tm .box_expected (other , box_with_array )
1452
- result = s + other
1453
- exp = DatetimeIndex ([Timestamp ("2001-1-1" ), Timestamp ("2000-2-29" )])
1454
- exp = tm .box_expected (exp , box_with_array )
1455
- tm .assert_equal (result , exp )
1456
-
1457
- # same offset
1458
- other = pd .Index (
1441
+ @pytest .mark .parametrize (
1442
+ "other" ,
1443
+ [
1444
+ np .array ([pd .offsets .MonthEnd (), pd .offsets .Day (n = 2 )]),
1445
+ np .array ([pd .offsets .DateOffset (years = 1 ), pd .offsets .MonthEnd ()]),
1446
+ np .array ( # matching offsets
1459
1447
[pd .offsets .DateOffset (years = 1 ), pd .offsets .DateOffset (years = 1 )]
1460
- )
1461
- other = tm .box_expected (other , box_with_array )
1462
- result = s + other
1463
- exp = DatetimeIndex ([Timestamp ("2001-1-1" ), Timestamp ("2001-2-1" )])
1464
- exp = tm .box_expected (exp , box_with_array )
1465
- tm .assert_equal (result , exp )
1466
-
1467
- # TODO: overlap with test_dt64arr_add_mixed_offset_array?
1468
- def test_dt64arr_add_sub_offset_ndarray (self , tz_naive_fixture , box_with_array ):
1448
+ ),
1449
+ ],
1450
+ )
1451
+ @pytest .mark .parametrize ("op" , [operator .add , roperator .radd , operator .sub ])
1452
+ @pytest .mark .parametrize ("box_other" , [True , False ])
1453
+ def test_dt64arr_add_sub_offset_array (
1454
+ self , tz_naive_fixture , box_with_array , box_other , op , other
1455
+ ):
1469
1456
# GH#18849
1457
+ # GH#10699 array of offsets
1470
1458
1471
1459
tz = tz_naive_fixture
1472
1460
dti = pd .date_range ("2017-01-01" , periods = 2 , tz = tz )
1473
1461
dtarr = tm .box_expected (dti , box_with_array )
1474
1462
1475
1463
other = np .array ([pd .offsets .MonthEnd (), pd .offsets .Day (n = 2 )])
1464
+ expected = DatetimeIndex ([op (dti [n ], other [n ]) for n in range (len (dti ))])
1465
+ expected = tm .box_expected (expected , box_with_array )
1466
+
1467
+ if box_other :
1468
+ other = tm .box_expected (other , box_with_array )
1476
1469
1477
1470
warn = PerformanceWarning
1478
- if box_with_array is pd .DataFrame and tz is not None :
1471
+ if box_with_array is pd .DataFrame and not ( tz is None and not box_other ) :
1479
1472
warn = None
1480
-
1481
- with tm .assert_produces_warning (warn ):
1482
- res = dtarr + other
1483
- expected = DatetimeIndex (
1484
- [dti [n ] + other [n ] for n in range (len (dti ))], name = dti .name , freq = "infer"
1485
- )
1486
- expected = tm .box_expected (expected , box_with_array )
1487
- tm .assert_equal (res , expected )
1488
-
1489
1473
with tm .assert_produces_warning (warn ):
1490
- res2 = other + dtarr
1491
- tm .assert_equal (res2 , expected )
1474
+ res = op (dtarr , other )
1492
1475
1493
- with tm .assert_produces_warning (warn ):
1494
- res = dtarr - other
1495
- expected = DatetimeIndex (
1496
- [dti [n ] - other [n ] for n in range (len (dti ))], name = dti .name , freq = "infer"
1497
- )
1498
- expected = tm .box_expected (expected , box_with_array )
1499
1476
tm .assert_equal (res , expected )
1500
1477
1501
1478
@pytest .mark .parametrize (
@@ -1905,9 +1882,9 @@ def test_dt64_mul_div_numeric_invalid(self, one, dt64_series):
1905
1882
1906
1883
# TODO: parametrize over box
1907
1884
@pytest .mark .parametrize ("op" , ["__add__" , "__radd__" , "__sub__" , "__rsub__" ])
1908
- @pytest .mark .parametrize ("tz" , [None , "Asia/Tokyo" ])
1909
- def test_dt64_series_add_intlike (self , tz , op ):
1885
+ def test_dt64_series_add_intlike (self , tz_naive_fixture , op ):
1910
1886
# GH#19123
1887
+ tz = tz_naive_fixture
1911
1888
dti = pd .DatetimeIndex (["2016-01-02" , "2016-02-03" , "NaT" ], tz = tz )
1912
1889
ser = Series (dti )
1913
1890
@@ -2376,12 +2353,9 @@ def test_ufunc_coercions(self):
2376
2353
tm .assert_index_equal (result , exp )
2377
2354
assert result .freq == exp .freq
2378
2355
2379
- @pytest .mark .parametrize (
2380
- "names" , [("foo" , None , None ), ("baz" , "bar" , None ), ("bar" , "bar" , "bar" )]
2381
- )
2382
- @pytest .mark .parametrize ("tz" , [None , "America/Chicago" ])
2383
- def test_dti_add_series (self , tz , names ):
2356
+ def test_dti_add_series (self , tz_naive_fixture , names ):
2384
2357
# GH#13905
2358
+ tz = tz_naive_fixture
2385
2359
index = DatetimeIndex (
2386
2360
["2016-06-28 05:30" , "2016-06-28 05:31" ], tz = tz , name = names [0 ]
2387
2361
)
@@ -2403,9 +2377,6 @@ def test_dti_add_series(self, tz, names):
2403
2377
tm .assert_index_equal (result4 , expected )
2404
2378
2405
2379
@pytest .mark .parametrize ("op" , [operator .add , roperator .radd , operator .sub ])
2406
- @pytest .mark .parametrize (
2407
- "names" , [(None , None , None ), ("foo" , "bar" , None ), ("foo" , "foo" , "foo" )]
2408
- )
2409
2380
def test_dti_addsub_offset_arraylike (
2410
2381
self , tz_naive_fixture , names , op , index_or_series
2411
2382
):
0 commit comments