Skip to content

Commit e5f2c97

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

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pandas/core/indexes/base.py

+12-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,10 +96,20 @@ def cmp_method(self, other):
9596
if needs_i8_conversion(self) and needs_i8_conversion(other):
9697
return self._evaluate_compare(other, op)
9798

98-
if is_object_dtype(self) and self.nlevels == 1:
99+
self_dtype = self.values.dtype
100+
other_dtype = np.asarray(other).dtype
101+
102+
if is_object_dtype(self_dtype) and self.nlevels == 1:
99103
# don't pass MultiIndex
100104
with np.errstate(all='ignore'):
101105
result = ops._comp_method_OBJECT_ARRAY(op, self.values, other)
106+
107+
elif ((self_dtype.type != other_dtype.type) and not
108+
(is_numeric_dtype(self_dtype) and
109+
is_numeric_dtype(other_dtype))):
110+
# short-circuit on dtype inequity
111+
result = op is not operator.eq
112+
102113
else:
103114
with np.errstate(all='ignore'):
104115
result = op(self.values, np.asarray(other))

0 commit comments

Comments
 (0)