Skip to content

BUG: assert_extension_array_equal using the wrong dtype #55812

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
Nov 6, 2023
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ Datetimelike
^^^^^^^^^^^^
- Bug in :class:`DatetimeIndex` when passing an object-dtype ndarray of float objects and a ``tz`` incorrectly localizing the result (:issue:`55780`)
- Bug in :func:`concat` raising ``AttributeError`` when concatenating all-NA DataFrame with :class:`DatetimeTZDtype` dtype DataFrame. (:issue:`52093`)
- Bug in :func:`testing.assert_extension_array_equal` that could use the wrong unit when comparing resolutions (:issue:`55730`)
- Bug in :func:`to_datetime` and :class:`DatetimeIndex` when passing a list of mixed-string-and-numeric types incorrectly raising (:issue:`55780`)
- Bug in :meth:`DatetimeIndex.union` returning object dtype for tz-aware indexes with the same timezone but different units (:issue:`55238`)
- Bug in :meth:`Index.is_monotonic_increasing` and :meth:`Index.is_monotonic_decreasing` always caching :meth:`Index.is_unique` as ``True`` when first value in index is ``NaT`` (:issue:`55755`)
Expand Down
2 changes: 1 addition & 1 deletion pandas/_testing/asserters.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ def assert_extension_array_equal(
else:
l_unit = np.datetime_data(left.dtype)[0]
if not isinstance(right.dtype, np.dtype):
r_unit = cast(DatetimeTZDtype, left.dtype).unit
r_unit = cast(DatetimeTZDtype, right.dtype).unit
else:
r_unit = np.datetime_data(right.dtype)[0]
if (
Expand Down
15 changes: 14 additions & 1 deletion pandas/tests/util/test_assert_extension_array_equal.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import numpy as np
import pytest

from pandas import array
from pandas import (
Timestamp,
array,
)
import pandas._testing as tm
from pandas.core.arrays.sparse import SparseArray

Expand Down Expand Up @@ -111,3 +114,13 @@ def test_assert_extension_array_equal_ignore_dtype_mismatch(right_dtype):
left = array([1, 2, 3], dtype="Int64")
right = array([1, 2, 3], dtype=right_dtype)
tm.assert_extension_array_equal(left, right, check_dtype=False)


def test_assert_extension_array_equal_time_units():
# https://github.com/pandas-dev/pandas/issues/55730
timestamp = Timestamp("2023-11-04T12")
naive = array([timestamp], dtype="datetime64[ns]")
utc = array([timestamp], dtype="datetime64[ns, UTC]")

tm.assert_extension_array_equal(naive, utc, check_dtype=False)
tm.assert_extension_array_equal(utc, naive, check_dtype=False)