Skip to content

REF: IntervalIndex.equals defer to IntervalArray.equals #36871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pandas/core/arrays/_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
from pandas.util._decorators import cache_readonly, doc
from pandas.util._validators import validate_fillna_kwargs

from pandas.core.dtypes.common import is_dtype_equal
from pandas.core.dtypes.inference import is_array_like
from pandas.core.dtypes.missing import array_equivalent

from pandas.core import missing
from pandas.core.algorithms import take, unique
Expand Down Expand Up @@ -115,6 +117,13 @@ def T(self: _T) -> _T:

# ------------------------------------------------------------------------

def equals(self, other) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is hitting this one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now the implementation used by PandasArray.equals

if type(self) is not type(other):
return False
if not is_dtype_equal(self.dtype, other.dtype):
return False
return bool(array_equivalent(self._ndarray, other._ndarray))

def _values_for_argsort(self):
return self._ndarray

Expand Down
10 changes: 10 additions & 0 deletions pandas/core/arrays/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,16 @@ def astype(self, dtype, copy=True):
msg = f"Cannot cast {type(self).__name__} to dtype {dtype}"
raise TypeError(msg) from err

def equals(self, other) -> bool:
if type(self) != type(other):
return False

return bool(
self.closed == other.closed
and self.left.equals(other.left)
and self.right.equals(other.right)
)

@classmethod
def _concat_same_type(cls, to_concat):
"""
Expand Down
13 changes: 2 additions & 11 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -983,19 +983,10 @@ def equals(self, other: object) -> bool:
if self.is_(other):
return True

# if we can coerce to an IntervalIndex then we can compare
if not isinstance(other, IntervalIndex):
if not is_interval_dtype(other):
return False
other = Index(other)
if not isinstance(other, IntervalIndex):
return False
return False

return (
self.left.equals(other.left)
and self.right.equals(other.right)
and self.closed == other.closed
)
return self._data.equals(other._data)

# --------------------------------------------------------------------
# Set Operations
Expand Down