Skip to content

Commit 2fc1d27

Browse files
Update test_operators.py
1 parent 19e3711 commit 2fc1d27

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

pandas/tests/arrays/categorical/test_operators.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from pandas import Categorical, DataFrame, Series, date_range
88
from pandas.tests.arrays.categorical.common import TestCategorical
99
import pandas.util.testing as tm
10+
import warnings
1011

1112

1213
class TestCategoricalOpsWithFactor(TestCategorical):
@@ -193,8 +194,14 @@ def test_comparison_of_ordered_categorical_with_nan_to_scalar(
193194
# values should be evaluated as False
194195

195196
cat = Categorical([1, 2, 3, None], categories=[1, 2, 3], ordered=True)
196-
197-
assert getattr(cat, compare_operators_no_eq_ne)(2)[-1] == False
197+
scalar = 2
198+
199+
with warnings.catch_warnings():
200+
warnings.simplefilter("ignore", RuntimeWarning)
201+
actual = getattr(cat, compare_operators_no_eq_ne)(scalar)
202+
expected = getattr(np.array(cat), compare_operators_no_eq_ne)(scalar)
203+
tm.assert_numpy_array_equal(actual, expected)
204+
198205

199206
def test_comparison_of_ordered_categorical_with_nan_to_listlike(
200207
self, compare_operators_no_eq_ne):
@@ -204,7 +211,12 @@ def test_comparison_of_ordered_categorical_with_nan_to_listlike(
204211

205212
cat = Categorical([1, 2, 3, None], categories=[1, 2, 3], ordered=True)
206213
other = Categorical([2, 2, 2, 2], categories=[1, 2, 3], ordered=True)
207-
assert getattr(cat, compare_operators_no_eq_ne)(other)[-1] == False
214+
215+
with warnings.catch_warnings():
216+
warnings.simplefilter("ignore", RuntimeWarning)
217+
actual = getattr(cat, compare_operators_no_eq_ne)(other)
218+
expected = getattr(np.array(cat), compare_operators_no_eq_ne)(2)
219+
tm.assert_numpy_array_equal(actual, expected)
208220

209221
@pytest.mark.parametrize('data,reverse,base', [
210222
(list("abc"), list("cba"), list("bbb")),

0 commit comments

Comments
 (0)