Skip to content

BUG: DTI/TDI.equals with i8 #36744

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 5 commits into from
Oct 2, 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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ Datetimelike
- Bug in :meth:`DatetimeIndex.searchsorted`, :meth:`TimedeltaIndex.searchsorted`, :meth:`PeriodIndex.searchsorted`, and :meth:`Series.searchsorted` with ``datetime64``, ``timedelta64`` or ``Period`` dtype placement of ``NaT`` values being inconsistent with ``NumPy`` (:issue:`36176`, :issue:`36254`)
- Inconsistency in :class:`DatetimeArray`, :class:`TimedeltaArray`, and :class:`PeriodArray` setitem casting arrays of strings to datetimelike scalars but not scalar strings (:issue:`36261`)
- Bug in :class:`DatetimeIndex.shift` incorrectly raising when shifting empty indexes (:issue:`14811`)

- Bug in :meth:`DatetimeIndex.equals` and :meth:`TimedeltaIndex.equals` incorrectly considering ``int64`` indexes as equal (:issue:`36744`)

Timedelta
^^^^^^^^^
Expand Down
2 changes: 2 additions & 0 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ def equals(self, other: object) -> bool:

if not isinstance(other, Index):
return False
elif other.dtype.kind in ["f", "i", "u", "c"]:
return False
elif not isinstance(other, type(self)):
try:
other = type(self)(other)
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/ops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,9 @@ def _should_reindex_frame_op(
if fill_value is None and level is None and axis is default_axis:
# TODO: any other cases we should handle here?
cols = left.columns.intersection(right.columns)
if not (cols.equals(left.columns) and cols.equals(right.columns)):

if len(cols) and not (cols.equals(left.columns) and cols.equals(right.columns)):
# TODO: is there a shortcut available when len(cols) == 0?
return True

return False
Expand Down
14 changes: 7 additions & 7 deletions pandas/tests/computation/test_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,15 +1054,15 @@ def test_complex_series_frame_alignment(self, engine, parser):
m2, n, data_gen_f=f, r_idx_type=r2, c_idx_type=c2
)
index = getattr(locals().get(obj_name), index_name)
s = Series(np.random.randn(n), index[:n])
ser = Series(np.random.randn(n), index[:n])

if r2 == "dt" or c2 == "dt":
if engine == "numexpr":
expected2 = df2.add(s)
expected2 = df2.add(ser)
else:
expected2 = df2 + s
expected2 = df2 + ser
else:
expected2 = df2 + s
expected2 = df2 + ser

if r1 == "dt" or c1 == "dt":
if engine == "numexpr":
Expand All @@ -1072,11 +1072,11 @@ def test_complex_series_frame_alignment(self, engine, parser):
else:
expected = expected2 + df

if should_warn(df2.index, s.index, df.index):
if should_warn(df2.index, ser.index, df.index):
with tm.assert_produces_warning(RuntimeWarning):
res = pd.eval("df2 + s + df", engine=engine, parser=parser)
res = pd.eval("df2 + ser + df", engine=engine, parser=parser)
else:
res = pd.eval("df2 + s + df", engine=engine, parser=parser)
res = pd.eval("df2 + ser + df", engine=engine, parser=parser)
assert res.shape == expected.shape
tm.assert_frame_equal(res, expected)

Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,10 @@ def test_getitem_preserves_freq(self):

result = index[:]
assert result.freq == index.freq

def test_not_equals_numeric(self):
index = self.create_index()

assert not index.equals(pd.Index(index.asi8))
assert not index.equals(pd.Index(index.asi8.astype("u8")))
assert not index.equals(pd.Index(index.asi8).astype("f8"))