Skip to content

BUG: recognize M8[ns, tzstr] #33885

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 6 commits into from
May 9, 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: 2 additions & 0 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,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 (
Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/dtypes/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/dtypes/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,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"))
Expand All @@ -294,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)
Expand Down