@@ -1421,8 +1421,9 @@ def test_dt64arr_add_sub_relativedelta_offsets(self, box_with_array, unit):
1421
1421
@pytest .mark .parametrize ("normalize" , [True , False ])
1422
1422
@pytest .mark .parametrize ("n" , [0 , 5 ])
1423
1423
@pytest .mark .parametrize ("unit" , ["s" , "ms" , "us" , "ns" ])
1424
+ @pytest .mark .parametrize ("tz" , [None , "US/Central" ])
1424
1425
def test_dt64arr_add_sub_DateOffsets (
1425
- self , box_with_array , n , normalize , cls_and_kwargs , unit
1426
+ self , box_with_array , n , normalize , cls_and_kwargs , unit , tz
1426
1427
):
1427
1428
# GH#10699
1428
1429
# assert vectorized operation matches pointwise operations
@@ -1444,33 +1445,33 @@ def test_dt64arr_add_sub_DateOffsets(
1444
1445
# passing n = 0 is invalid for these offset classes
1445
1446
return
1446
1447
1447
- vec = DatetimeIndex (
1448
- [
1449
- Timestamp ("2000-01-05 00:15:00" ),
1450
- Timestamp ("2000-01-31 00:23:00" ),
1451
- Timestamp ("2000-01-01" ),
1452
- Timestamp ("2000-03-31" ),
1453
- Timestamp ("2000-02-29" ),
1454
- Timestamp ("2000-12-31" ),
1455
- Timestamp ("2000-05-15" ),
1456
- Timestamp ("2001-06-15" ),
1457
- ]
1458
- ).as_unit (unit )
1448
+ vec = (
1449
+ DatetimeIndex (
1450
+ [
1451
+ Timestamp ("2000-01-05 00:15:00" ),
1452
+ Timestamp ("2000-01-31 00:23:00" ),
1453
+ Timestamp ("2000-01-01" ),
1454
+ Timestamp ("2000-03-31" ),
1455
+ Timestamp ("2000-02-29" ),
1456
+ Timestamp ("2000-12-31" ),
1457
+ Timestamp ("2000-05-15" ),
1458
+ Timestamp ("2001-06-15" ),
1459
+ ]
1460
+ )
1461
+ .as_unit (unit )
1462
+ .tz_localize (tz )
1463
+ )
1459
1464
vec = tm .box_expected (vec , box_with_array )
1460
1465
vec_items = vec .iloc [0 ] if box_with_array is pd .DataFrame else vec
1461
1466
1462
1467
offset_cls = getattr (pd .offsets , cls_name )
1463
-
1464
- # pandas.errors.PerformanceWarning: Non-vectorized DateOffset being
1465
- # applied to Series or DatetimeIndex
1466
- # we aren't testing that here, so ignore.
1467
-
1468
1468
offset = offset_cls (n , normalize = normalize , ** kwargs )
1469
1469
1470
1470
# TODO(GH#55564): as_unit will be unnecessary
1471
1471
expected = DatetimeIndex ([x + offset for x in vec_items ]).as_unit (unit )
1472
1472
expected = tm .box_expected (expected , box_with_array )
1473
1473
tm .assert_equal (expected , vec + offset )
1474
+ tm .assert_equal (expected , offset + vec )
1474
1475
1475
1476
expected = DatetimeIndex ([x - offset for x in vec_items ]).as_unit (unit )
1476
1477
expected = tm .box_expected (expected , box_with_array )
@@ -1483,64 +1484,6 @@ def test_dt64arr_add_sub_DateOffsets(
1483
1484
with pytest .raises (TypeError , match = msg ):
1484
1485
offset - vec
1485
1486
1486
- def test_dt64arr_add_sub_DateOffset (self , box_with_array ):
1487
- # GH#10699
1488
- s = date_range ("2000-01-01" , "2000-01-31" , name = "a" )
1489
- s = tm .box_expected (s , box_with_array )
1490
- result = s + DateOffset (years = 1 )
1491
- result2 = DateOffset (years = 1 ) + s
1492
- exp = date_range ("2001-01-01" , "2001-01-31" , name = "a" )._with_freq (None )
1493
- exp = tm .box_expected (exp , box_with_array )
1494
- tm .assert_equal (result , exp )
1495
- tm .assert_equal (result2 , exp )
1496
-
1497
- result = s - DateOffset (years = 1 )
1498
- exp = date_range ("1999-01-01" , "1999-01-31" , name = "a" )._with_freq (None )
1499
- exp = tm .box_expected (exp , box_with_array )
1500
- tm .assert_equal (result , exp )
1501
-
1502
- s = DatetimeIndex (
1503
- [
1504
- Timestamp ("2000-01-15 00:15:00" , tz = "US/Central" ),
1505
- Timestamp ("2000-02-15" , tz = "US/Central" ),
1506
- ],
1507
- name = "a" ,
1508
- )
1509
- s = tm .box_expected (s , box_with_array )
1510
- result = s + pd .offsets .Day ()
1511
- result2 = pd .offsets .Day () + s
1512
- exp = DatetimeIndex (
1513
- [
1514
- Timestamp ("2000-01-16 00:15:00" , tz = "US/Central" ),
1515
- Timestamp ("2000-02-16" , tz = "US/Central" ),
1516
- ],
1517
- name = "a" ,
1518
- )
1519
- exp = tm .box_expected (exp , box_with_array )
1520
- tm .assert_equal (result , exp )
1521
- tm .assert_equal (result2 , exp )
1522
-
1523
- s = DatetimeIndex (
1524
- [
1525
- Timestamp ("2000-01-15 00:15:00" , tz = "US/Central" ),
1526
- Timestamp ("2000-02-15" , tz = "US/Central" ),
1527
- ],
1528
- name = "a" ,
1529
- )
1530
- s = tm .box_expected (s , box_with_array )
1531
- result = s + pd .offsets .MonthEnd ()
1532
- result2 = pd .offsets .MonthEnd () + s
1533
- exp = DatetimeIndex (
1534
- [
1535
- Timestamp ("2000-01-31 00:15:00" , tz = "US/Central" ),
1536
- Timestamp ("2000-02-29" , tz = "US/Central" ),
1537
- ],
1538
- name = "a" ,
1539
- )
1540
- exp = tm .box_expected (exp , box_with_array )
1541
- tm .assert_equal (result , exp )
1542
- tm .assert_equal (result2 , exp )
1543
-
1544
1487
@pytest .mark .parametrize (
1545
1488
"other" ,
1546
1489
[
0 commit comments