diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 598c4dca9ce88..0c8169b4818a0 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -112,17 +112,11 @@ def cmp_method(self, other): with np.errstate(all="ignore"): result = op(self.values, np.asarray(other)) - # technically we could support bool dtyped Index - # for now just return the indexing array directly if is_bool_dtype(result): return result - try: - return Index(result) - except TypeError: - return result + return ops.invalid_comparison(self, other, op) name = "__{name}__".format(name=op.__name__) - # TODO: docstring? return set_function_name(cmp_method, name, cls) diff --git a/pandas/tests/indexes/test_numpy_compat.py b/pandas/tests/indexes/test_numpy_compat.py index f9ca1bca04165..645ad19ea4cc9 100644 --- a/pandas/tests/indexes/test_numpy_compat.py +++ b/pandas/tests/indexes/test_numpy_compat.py @@ -118,4 +118,7 @@ def test_elementwise_comparison_warning(): # this test. idx = Index([1, 2]) with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - idx == "a" + result = idx == "a" + + expected = np.array([False, False]) + tm.assert_numpy_array_equal(result, expected)