@@ -85,6 +85,52 @@ def test_dt64arr_cmp_scalar_invalid(self, other, tz_naive_fixture, box_with_arra
85
85
dtarr = tm .box_expected (rng , box_with_array )
86
86
assert_invalid_comparison (dtarr , other , box_with_array )
87
87
88
+ @pytest .mark .parametrize (
89
+ "other" ,
90
+ [
91
+ list (range (10 )),
92
+ np .arange (10 ),
93
+ np .arange (10 ).astype (np .float32 ),
94
+ np .arange (10 ).astype (object ),
95
+ pd .timedelta_range ("1ns" , periods = 10 ).array ,
96
+ np .array (pd .timedelta_range ("1ns" , periods = 10 )),
97
+ list (pd .timedelta_range ("1ns" , periods = 10 )),
98
+ pd .timedelta_range ("1 Day" , periods = 10 ).astype (object ),
99
+ pd .period_range ("1971-01-01" , freq = "D" , periods = 10 ).array ,
100
+ pd .period_range ("1971-01-01" , freq = "D" , periods = 10 ).astype (object ),
101
+ ],
102
+ )
103
+ def test_dt64arr_cmp_arraylike_invalid (self , other , tz_naive_fixture ):
104
+ # We don't parametrize this over box_with_array because listlike
105
+ # other plays poorly with assert_invalid_comparison reversed checks
106
+ tz = tz_naive_fixture
107
+
108
+ dta = date_range ("1970-01-01" , freq = "ns" , periods = 10 , tz = tz )._data
109
+ assert_invalid_comparison (dta , other , tm .to_array )
110
+
111
+ def test_dt64arr_cmp_mixed_invalid (self , tz_naive_fixture ):
112
+ tz = tz_naive_fixture
113
+
114
+ dta = date_range ("1970-01-01" , freq = "h" , periods = 5 , tz = tz )._data
115
+
116
+ other = np .array ([0 , 1 , 2 , dta [3 ], pd .Timedelta (days = 1 )])
117
+ result = dta == other
118
+ expected = np .array ([False , False , False , True , False ])
119
+ tm .assert_numpy_array_equal (result , expected )
120
+
121
+ result = dta != other
122
+ tm .assert_numpy_array_equal (result , ~ expected )
123
+
124
+ msg = "Invalid comparison between|Cannot compare type|not supported between"
125
+ with pytest .raises (TypeError , match = msg ):
126
+ dta < other
127
+ with pytest .raises (TypeError , match = msg ):
128
+ dta > other
129
+ with pytest .raises (TypeError , match = msg ):
130
+ dta <= other
131
+ with pytest .raises (TypeError , match = msg ):
132
+ dta >= other
133
+
88
134
def test_dt64arr_nat_comparison (self , tz_naive_fixture , box_with_array ):
89
135
# GH#22242, GH#22163 DataFrame considered NaT == ts incorrectly
90
136
tz = tz_naive_fixture
0 commit comments