Skip to content

Commit c2b7343

Browse files
Update test_operators.py
1 parent 9464f72 commit c2b7343

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

pandas/tests/arrays/categorical/test_operators.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,27 @@ def test_comparison_with_unknown_scalars(self):
185185
tm.assert_numpy_array_equal(cat != 4,
186186
np.array([True, True, True]))
187187

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):
189190
# https://github.com/pandas-dev/pandas/issues/26504
190191
# BUG: fix ordered categorical comparison with missing values (#26504 )
191192
# and following comparisons with scalars in categories with missing
192193
# values should be evaluated as False
193194

194195
cat = Categorical([1, 2, 3, None], categories=[1, 2, 3], ordered=True)
195196

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
198198

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+
199209
@pytest.mark.parametrize('data,reverse,base', [
200210
(list("abc"), list("cba"), list("bbb")),
201211
([1, 2, 3], [3, 2, 1], [2, 2, 2])])

0 commit comments

Comments
 (0)