Skip to content

Commit 8bb9bcf

Browse files
committed
fix categorical comparison with missing values
1 parent 045c912 commit 8bb9bcf

File tree

2 files changed

+1
-5
lines changed

2 files changed

+1
-5
lines changed

pandas/core/arrays/categorical.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ def f(self, other):
104104

105105
# check for NaN in self
106106
mask = (self._codes == -1)
107-
if mask.any():
108-
# comparison to missing values NaN leads to False
109-
ret[mask] = False
107+
ret[mask] = False
110108
return ret
111109
else:
112110
if op == '__eq__':

pandas/tests/arrays/categorical/test_operators.py

-2
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ def test_comparison_of_ordered_categorical_with_nan_to_scalar(
195195

196196
cat = Categorical([1, 2, 3, None], categories=[1, 2, 3], ordered=True)
197197
scalar = 2
198-
199198
with warnings.catch_warnings():
200199
warnings.simplefilter("ignore", RuntimeWarning)
201200
expected = getattr(np.array(cat),
@@ -211,7 +210,6 @@ def test_comparison_of_ordered_categorical_with_nan_to_listlike(
211210

212211
cat = Categorical([1, 2, 3, None], categories=[1, 2, 3], ordered=True)
213212
other = Categorical([2, 2, 2, 2], categories=[1, 2, 3], ordered=True)
214-
215213
with warnings.catch_warnings():
216214
warnings.simplefilter("ignore", RuntimeWarning)
217215
expected = getattr(np.array(cat), compare_operators_no_eq_ne)(2)

0 commit comments

Comments
 (0)