From 9f8790d655ec248664ef57189272b43eadca40aa Mon Sep 17 00:00:00 2001 From: tp Date: Wed, 21 Oct 2020 21:14:38 +0100 Subject: [PATCH 1/2] BUG: Index._id --- pandas/core/indexes/base.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 6b71e455782e3..9f70c017e9169 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -220,7 +220,7 @@ def _outer_indexer(self, left, right): _typ = "index" _data: Union[ExtensionArray, np.ndarray] - _id: _Identity + _id: Optional[_Identity] = None _name: Label = None # MultiIndex.levels previously allowed setting the index name. We # don't allow this anymore, and raise if it happens rather than @@ -541,10 +541,10 @@ def is_(self, other) -> bool: -------- Index.identical : Works like ``Index.is_`` but also checks metadata. """ - try: - return self._id is other._id - except AttributeError: - return False + if self is other: + return True + else: + return self._id is not None and self._id is getattr(other, "_id", Ellipsis) def _reset_identity(self) -> None: """ From 677910d674234c0c2674d1d6b43bba5bbd265fdc Mon Sep 17 00:00:00 2001 From: tp Date: Thu, 22 Oct 2020 08:14:01 +0100 Subject: [PATCH 2/2] Make comparions more explicit --- pandas/core/indexes/base.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 9f70c017e9169..3b28361399fba 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -543,8 +543,12 @@ def is_(self, other) -> bool: """ if self is other: return True + elif not hasattr(other, "_id"): + return False + elif com.any_none(self._id, other._id): + return False else: - return self._id is not None and self._id is getattr(other, "_id", Ellipsis) + return self._id is other._id def _reset_identity(self) -> None: """