Skip to content

Commit 06a3a03

Browse files
TomAugspurgerjreback
authored andcommitted
Surface NumPy FutureWarning about comparisons (#26966)
1 parent a4a18a9 commit 06a3a03

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

pandas/core/indexes/base.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,8 @@ def cmp_method(self, other):
7676
result = ops._comp_method_OBJECT_ARRAY(op, self.values, other)
7777

7878
else:
79-
80-
# numpy will show a DeprecationWarning on invalid elementwise
81-
# comparisons, this will raise in the future
82-
with warnings.catch_warnings(record=True):
83-
warnings.filterwarnings("ignore", "elementwise", FutureWarning)
84-
with np.errstate(all='ignore'):
85-
result = op(self.values, np.asarray(other))
79+
with np.errstate(all='ignore'):
80+
result = op(self.values, np.asarray(other))
8681

8782
# technically we could support bool dtyped Index
8883
# for now just return the indexing array directly

pandas/tests/indexes/test_numpy_compat.py

+13
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,16 @@ def test_numpy_ufuncs_other(indices, func):
8080
else:
8181
with pytest.raises(Exception):
8282
func(idx)
83+
84+
85+
def test_elementwise_comparison_warning():
86+
# https://github.com/pandas-dev/pandas/issues/22698#issuecomment-458968300
87+
# np.array([1, 2]) == 'a' returns False, and produces a
88+
# FutureWarning that it'll be [False, False] in the future.
89+
# We just want to ensure that comes through.
90+
# When NumPy dev actually enforces this change, we'll need to skip
91+
# this test.
92+
idx = Index([1, 2])
93+
with tm.assert_produces_warning(FutureWarning,
94+
check_stacklevel=False):
95+
idx == 'a'

0 commit comments

Comments
 (0)