Skip to content
Open
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
21 changes: 19 additions & 2 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,26 @@ def equals(self, other: Any) -> bool:

if not isinstance(other, Index):
return False
elif other.dtype.kind in "iufc":

if len(self) != len(other):
return False

self_unit = getattr(self, "unit", None)
other_unit = getattr(other, "unit", None)

if self_unit is not None and other_unit is not None and self_unit != other_unit:
if getattr(self.dtype, "tz", None) == getattr(other.dtype, "tz", None):
try:
other_values = other._values
if hasattr(other_values, "as_unit") and hasattr(
self._values, "equals"
):
return self._values.equals(other_values.as_unit(self_unit))
except (ValueError, TypeError, AttributeError):
return False
if other.dtype.kind in "iufc":
return False

elif not isinstance(other, type(self)):
should_try = False
inferable = self._data._infer_matches
Expand All @@ -267,7 +285,6 @@ def equals(self, other: Any) -> bool:
return False

if self.dtype != other.dtype:
# have different timezone
return False

return np.array_equal(self.asi8, other.asi8)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/datetimes/test_setops.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def test_intersection_same_timezone_different_units(self):
# Test intersection
result = idx1.intersection(idx2)
expected = date_range("2000-01-01", periods=3, tz=tz).as_unit("ns")
tm.assert_index_equal(result, expected)
tm.assert_index_equal(result, expected, exact=False)

def test_symmetric_difference_same_timezone_different_units(self):
# GH 60080 - fix timezone being changed to UTC when units differ
Expand Down
Loading