@@ -348,28 +348,6 @@ def test_dt64arr_timestamp_equality(self, box_with_array):
348
348
expected = tm .box_expected ([False , False ], xbox )
349
349
tm .assert_equal (result , expected )
350
350
351
- @pytest .mark .parametrize (
352
- "op" ,
353
- [operator .eq , operator .ne , operator .gt , operator .ge , operator .lt , operator .le ],
354
- )
355
- def test_comparison_tzawareness_compat (self , op ):
356
- # GH#18162
357
- dr = pd .date_range ("2016-01-01" , periods = 6 )
358
- dz = dr .tz_localize ("US/Pacific" )
359
-
360
- # Check that there isn't a problem aware-aware and naive-naive do not
361
- # raise
362
- naive_series = Series (dr )
363
- aware_series = Series (dz )
364
- msg = "Cannot compare tz-naive and tz-aware"
365
- with pytest .raises (TypeError , match = msg ):
366
- op (dz , naive_series )
367
- with pytest .raises (TypeError , match = msg ):
368
- op (dr , aware_series )
369
-
370
- # TODO: implement _assert_tzawareness_compat for the reverse
371
- # comparison with the Series on the left-hand side
372
-
373
351
374
352
class TestDatetimeIndexComparisons :
375
353
@@ -599,15 +577,18 @@ def test_comparison_tzawareness_compat(self, op, box_df_fail):
599
577
with pytest .raises (TypeError , match = msg ):
600
578
op (dz , np .array (list (dr ), dtype = object ))
601
579
602
- # Check that there isn't a problem aware-aware and naive-naive do not
603
- # raise
580
+ # The aware==aware and naive==naive comparisons should *not* raise
604
581
assert_all (dr == dr )
605
- assert_all (dz == dz )
582
+ assert_all (dr == list (dr ))
583
+ assert_all (list (dr ) == dr )
584
+ assert_all (np .array (list (dr ), dtype = object ) == dr )
585
+ assert_all (dr == np .array (list (dr ), dtype = object ))
606
586
607
- # FIXME: DataFrame case fails to raise for == and !=, wrong
608
- # message for inequalities
609
- assert (dr == list (dr )).all ()
610
- assert (dz == list (dz )).all ()
587
+ assert_all (dz == dz )
588
+ assert_all (dz == list (dz ))
589
+ assert_all (list (dz ) == dz )
590
+ assert_all (np .array (list (dz ), dtype = object ) == dz )
591
+ assert_all (dz == np .array (list (dz ), dtype = object ))
611
592
612
593
@pytest .mark .parametrize (
613
594
"op" ,
@@ -844,6 +825,7 @@ def test_dt64arr_isub_timedeltalike_scalar(
844
825
rng -= two_hours
845
826
tm .assert_equal (rng , expected )
846
827
828
+ # TODO: redundant with test_dt64arr_add_timedeltalike_scalar
847
829
def test_dt64arr_add_td64_scalar (self , box_with_array ):
848
830
# scalar timedeltas/np.timedelta64 objects
849
831
# operate with np.timedelta64 correctly
@@ -1709,14 +1691,12 @@ def test_operators_datetimelike(self):
1709
1691
dt1 - dt2
1710
1692
dt2 - dt1
1711
1693
1712
- # ## datetime64 with timetimedelta ###
1694
+ # datetime64 with timetimedelta
1713
1695
dt1 + td1
1714
1696
td1 + dt1
1715
1697
dt1 - td1
1716
- # TODO: Decide if this ought to work.
1717
- # td1 - dt1
1718
1698
1719
- # ## timetimedelta with datetime64 ###
1699
+ # timetimedelta with datetime64
1720
1700
td1 + dt1
1721
1701
dt1 + td1
1722
1702
@@ -1914,7 +1894,7 @@ def test_dt64_series_add_intlike(self, tz, op):
1914
1894
with pytest .raises (TypeError , match = msg ):
1915
1895
method (other )
1916
1896
with pytest .raises (TypeError , match = msg ):
1917
- method (other . values )
1897
+ method (np . array ( other ) )
1918
1898
with pytest .raises (TypeError , match = msg ):
1919
1899
method (pd .Index (other ))
1920
1900
@@ -2380,34 +2360,34 @@ def test_ufunc_coercions(self):
2380
2360
idx = date_range ("2011-01-01" , periods = 3 , freq = "2D" , name = "x" )
2381
2361
2382
2362
delta = np .timedelta64 (1 , "D" )
2363
+ exp = date_range ("2011-01-02" , periods = 3 , freq = "2D" , name = "x" )
2383
2364
for result in [idx + delta , np .add (idx , delta )]:
2384
2365
assert isinstance (result , DatetimeIndex )
2385
- exp = date_range ("2011-01-02" , periods = 3 , freq = "2D" , name = "x" )
2386
2366
tm .assert_index_equal (result , exp )
2387
2367
assert result .freq == "2D"
2388
2368
2369
+ exp = date_range ("2010-12-31" , periods = 3 , freq = "2D" , name = "x" )
2389
2370
for result in [idx - delta , np .subtract (idx , delta )]:
2390
2371
assert isinstance (result , DatetimeIndex )
2391
- exp = date_range ("2010-12-31" , periods = 3 , freq = "2D" , name = "x" )
2392
2372
tm .assert_index_equal (result , exp )
2393
2373
assert result .freq == "2D"
2394
2374
2395
2375
delta = np .array (
2396
2376
[np .timedelta64 (1 , "D" ), np .timedelta64 (2 , "D" ), np .timedelta64 (3 , "D" )]
2397
2377
)
2378
+ exp = DatetimeIndex (
2379
+ ["2011-01-02" , "2011-01-05" , "2011-01-08" ], freq = "3D" , name = "x"
2380
+ )
2398
2381
for result in [idx + delta , np .add (idx , delta )]:
2399
2382
assert isinstance (result , DatetimeIndex )
2400
- exp = DatetimeIndex (
2401
- ["2011-01-02" , "2011-01-05" , "2011-01-08" ], freq = "3D" , name = "x"
2402
- )
2403
2383
tm .assert_index_equal (result , exp )
2404
2384
assert result .freq == "3D"
2405
2385
2386
+ exp = DatetimeIndex (
2387
+ ["2010-12-31" , "2011-01-01" , "2011-01-02" ], freq = "D" , name = "x"
2388
+ )
2406
2389
for result in [idx - delta , np .subtract (idx , delta )]:
2407
2390
assert isinstance (result , DatetimeIndex )
2408
- exp = DatetimeIndex (
2409
- ["2010-12-31" , "2011-01-01" , "2011-01-02" ], freq = "D" , name = "x"
2410
- )
2411
2391
tm .assert_index_equal (result , exp )
2412
2392
assert result .freq == "D"
2413
2393
0 commit comments