From 2ce1bdfe6f60aea42065bc0063c3967f3a38ed0b Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 29 Apr 2020 18:38:05 -0700 Subject: [PATCH 1/3] BUG: recognizing M8[ns, tzstr] --- pandas/core/dtypes/dtypes.py | 2 ++ pandas/tests/dtypes/test_dtypes.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/pandas/core/dtypes/dtypes.py b/pandas/core/dtypes/dtypes.py index d7ba150e3ec9d..2d9bf4219de09 100644 --- a/pandas/core/dtypes/dtypes.py +++ b/pandas/core/dtypes/dtypes.py @@ -781,6 +781,8 @@ def __hash__(self) -> int: def __eq__(self, other: Any) -> bool: if isinstance(other, str): + if other.startswith("M8["): + other = "datetime64[" + other[3:] return other == self.name return ( diff --git a/pandas/tests/dtypes/test_dtypes.py b/pandas/tests/dtypes/test_dtypes.py index d0831ea514a64..87c8e84d5c778 100644 --- a/pandas/tests/dtypes/test_dtypes.py +++ b/pandas/tests/dtypes/test_dtypes.py @@ -276,12 +276,14 @@ def test_is_dtype(self, dtype): assert not DatetimeTZDtype.is_dtype(None) assert DatetimeTZDtype.is_dtype(dtype) assert DatetimeTZDtype.is_dtype("datetime64[ns, US/Eastern]") + assert DatetimeTZDtype.is_dtype("M8[ns, US/Eastern]") assert not DatetimeTZDtype.is_dtype("foo") assert DatetimeTZDtype.is_dtype(DatetimeTZDtype("ns", "US/Pacific")) assert not DatetimeTZDtype.is_dtype(np.float64) def test_equality(self, dtype): assert is_dtype_equal(dtype, "datetime64[ns, US/Eastern]") + assert is_dtype_equal(dtype, "M8[ns, US/Eastern]") assert is_dtype_equal(dtype, DatetimeTZDtype("ns", "US/Eastern")) assert not is_dtype_equal(dtype, "foo") assert not is_dtype_equal(dtype, DatetimeTZDtype("ns", "CET")) From bbb06de6a25e022e7a1f72a630a31dd87a406e8b Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 29 Apr 2020 18:41:39 -0700 Subject: [PATCH 2/3] test that fails on master --- pandas/tests/dtypes/test_dtypes.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/tests/dtypes/test_dtypes.py b/pandas/tests/dtypes/test_dtypes.py index 73dd53c0c75d9..b55ff92e3f6a4 100644 --- a/pandas/tests/dtypes/test_dtypes.py +++ b/pandas/tests/dtypes/test_dtypes.py @@ -296,6 +296,8 @@ def test_equality(self, dtype): # numpy compat assert is_dtype_equal(np.dtype("M8[ns]"), "datetime64[ns]") + assert dtype == "M8[ns, US/Eastern]" + def test_basic(self, dtype): assert is_datetime64tz_dtype(dtype) From 5f06e9dfad8fde9b15253301f989f4c5959aa122 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Sun, 3 May 2020 15:29:09 -0700 Subject: [PATCH 3/3] add test for pandas_dtype --- pandas/tests/dtypes/test_common.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index b9c8f3a8dd494..1708139a397ab 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -75,6 +75,10 @@ def test_numpy_string_dtype(self): "datetime64[ns, US/Eastern]", "datetime64[ns, Asia/Tokyo]", "datetime64[ns, UTC]", + # GH#33885 check that the M8 alias is understood + "M8[ns, US/Eastern]", + "M8[ns, Asia/Tokyo]", + "M8[ns, UTC]", ], ) def test_datetimetz_dtype(self, dtype):