Skip to content

Commit b6f2909

Browse files
authored
BUG: assert_extension_array_equal using the wrong dtype (#55812)
* Use the right dtype * Add to whatsnew * Switch whatsnew to 2.2.0.rst * Add test * isort
1 parent 95c2a7d commit b6f2909

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

doc/source/whatsnew/v2.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ Datetimelike
346346
- Bug in :class:`DatetimeIndex` construction when passing both a ``tz`` and either ``dayfirst`` or ``yearfirst`` ignoring dayfirst/yearfirst (:issue:`55813`)
347347
- Bug in :class:`DatetimeIndex` when passing an object-dtype ndarray of float objects and a ``tz`` incorrectly localizing the result (:issue:`55780`)
348348
- Bug in :func:`concat` raising ``AttributeError`` when concatenating all-NA DataFrame with :class:`DatetimeTZDtype` dtype DataFrame. (:issue:`52093`)
349+
- Bug in :func:`testing.assert_extension_array_equal` that could use the wrong unit when comparing resolutions (:issue:`55730`)
349350
- Bug in :func:`to_datetime` and :class:`DatetimeIndex` when passing a list of mixed-string-and-numeric types incorrectly raising (:issue:`55780`)
350351
- Bug in :meth:`DatetimeIndex.union` returning object dtype for tz-aware indexes with the same timezone but different units (:issue:`55238`)
351352
- 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`)

pandas/_testing/asserters.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ def assert_extension_array_equal(
745745
else:
746746
l_unit = np.datetime_data(left.dtype)[0]
747747
if not isinstance(right.dtype, np.dtype):
748-
r_unit = cast(DatetimeTZDtype, left.dtype).unit
748+
r_unit = cast(DatetimeTZDtype, right.dtype).unit
749749
else:
750750
r_unit = np.datetime_data(right.dtype)[0]
751751
if (

pandas/tests/util/test_assert_extension_array_equal.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import numpy as np
22
import pytest
33

4-
from pandas import array
4+
from pandas import (
5+
Timestamp,
6+
array,
7+
)
58
import pandas._testing as tm
69
from pandas.core.arrays.sparse import SparseArray
710

@@ -111,3 +114,13 @@ def test_assert_extension_array_equal_ignore_dtype_mismatch(right_dtype):
111114
left = array([1, 2, 3], dtype="Int64")
112115
right = array([1, 2, 3], dtype=right_dtype)
113116
tm.assert_extension_array_equal(left, right, check_dtype=False)
117+
118+
119+
def test_assert_extension_array_equal_time_units():
120+
# https://github.com/pandas-dev/pandas/issues/55730
121+
timestamp = Timestamp("2023-11-04T12")
122+
naive = array([timestamp], dtype="datetime64[ns]")
123+
utc = array([timestamp], dtype="datetime64[ns, UTC]")
124+
125+
tm.assert_extension_array_equal(naive, utc, check_dtype=False)
126+
tm.assert_extension_array_equal(utc, naive, check_dtype=False)

0 commit comments

Comments
 (0)