Skip to content

Commit 1fe02fa

Browse files
committed
COMPAT: work around deprecation warning on non-equal dtype comparisons
closes #20011
1 parent e3f6a5b commit 1fe02fa

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

pandas/core/indexes/base.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
is_datetime64_any_dtype,
4343
is_datetime64tz_dtype,
4444
is_timedelta64_dtype,
45+
is_numeric_dtype,
4546
needs_i8_conversion,
4647
is_iterator, is_list_like,
4748
is_scalar)
@@ -95,13 +96,24 @@ def cmp_method(self, other):
9596
if needs_i8_conversion(self) and needs_i8_conversion(other):
9697
return self._evaluate_compare(other, op)
9798

99+
other = np.asarray(other)
100+
self_dtype = self.values.dtype
101+
other_dtype = other.dtype
102+
98103
if is_object_dtype(self) and self.nlevels == 1:
99104
# don't pass MultiIndex
100105
with np.errstate(all='ignore'):
101106
result = ops._comp_method_OBJECT_ARRAY(op, self.values, other)
107+
108+
elif ((self_dtype.type != other_dtype.type) and not
109+
(is_numeric_dtype(self_dtype) and
110+
is_numeric_dtype(other_dtype))):
111+
# short-circuit on dtype inequity
112+
result = op is not operator.eq
113+
102114
else:
103115
with np.errstate(all='ignore'):
104-
result = op(self.values, np.asarray(other))
116+
result = op(self.values, other)
105117

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

0 commit comments

Comments
 (0)