@@ -185,17 +185,27 @@ def test_comparison_with_unknown_scalars(self):
185
185
tm .assert_numpy_array_equal (cat != 4 ,
186
186
np .array ([True , True , True ]))
187
187
188
- def test_comparison_of_ordered_categorical_with_nan_to_scalar (self ):
188
+ def test_comparison_of_ordered_categorical_with_nan_to_scalar (
189
+ self , compare_operators_no_eq_ne ):
189
190
# https://github.com/pandas-dev/pandas/issues/26504
190
191
# BUG: fix ordered categorical comparison with missing values (#26504 )
191
192
# and following comparisons with scalars in categories with missing
192
193
# values should be evaluated as False
193
194
194
195
cat = Categorical ([1 , 2 , 3 , None ], categories = [1 , 2 , 3 ], ordered = True )
195
196
196
- tm .assert_numpy_array_equal (cat <= 2 ,
197
- np .array ([True , True , False , False ]))
197
+ assert getattr (cat , compare_operators_no_eq_ne )(2 )[- 1 ] == False
198
198
199
+ def test_comparison_of_ordered_categorical_with_nan_to_listlike (
200
+ self , compare_operators_no_eq_ne ):
201
+ # https://github.com/pandas-dev/pandas/issues/26504
202
+ # and following comparisons of missing values in ordered Categorical
203
+ # with listlike should be evaluated as False
204
+
205
+ cat = Categorical ([1 , 2 , 3 , None ], categories = [1 , 2 , 3 ], ordered = True )
206
+ other = Categorical ([2 , 2 , 2 , 2 ], categories = [1 , 2 , 3 ], ordered = True )
207
+ assert getattr (cat , compare_operators_no_eq_ne )(other )[- 1 ] == False
208
+
199
209
@pytest .mark .parametrize ('data,reverse,base' , [
200
210
(list ("abc" ), list ("cba" ), list ("bbb" )),
201
211
([1 , 2 , 3 ], [3 , 2 , 1 ], [2 , 2 , 2 ])])
0 commit comments