Skip to content

Commit 69b25ee

Browse files
jbrockmendeljreback
authored andcommitted
CLN: use invalid_comparison for incorrect case in Index comparison (#27879)
1 parent eddeee5 commit 69b25ee

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

pandas/core/indexes/base.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,11 @@ def cmp_method(self, other):
116116
with np.errstate(all="ignore"):
117117
result = op(self.values, np.asarray(other))
118118

119-
# technically we could support bool dtyped Index
120-
# for now just return the indexing array directly
121119
if is_bool_dtype(result):
122120
return result
123-
try:
124-
return Index(result)
125-
except TypeError:
126-
return result
121+
return ops.invalid_comparison(self, other, op)
127122

128123
name = "__{name}__".format(name=op.__name__)
129-
# TODO: docstring?
130124
return set_function_name(cmp_method, name, cls)
131125

132126

pandas/tests/indexes/test_numpy_compat.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,7 @@ def test_elementwise_comparison_warning():
118118
# this test.
119119
idx = Index([1, 2])
120120
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
121-
idx == "a"
121+
result = idx == "a"
122+
123+
expected = np.array([False, False])
124+
tm.assert_numpy_array_equal(result, expected)

0 commit comments

Comments
 (0)