Skip to content

Commit ce5a112

Browse files
authored
REGR: Make comparisons consistent for PeriodDtype (#37270)
1 parent de5349a commit ce5a112

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

doc/source/whatsnew/v1.1.4.rst

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Fixed regressions
2121
- Fixed regression in :meth:`Series.astype` converting ``None`` to ``"nan"`` when casting to string (:issue:`36904`)
2222
- Fixed regression in :class:`RollingGroupby` causing a segmentation fault with Index of dtype object (:issue:`36727`)
2323
- Fixed regression in :meth:`DataFrame.resample(...).apply(...)` raised ``AttributeError`` when input was a :class:`DataFrame` and only a :class:`Series` was evaluated (:issue:`36951`)
24+
- Fixed regression in :class:`PeriodDtype` comparing both equal and unequal to its string representation (:issue:`37265`)
2425

2526
.. ---------------------------------------------------------------------------
2627

pandas/core/dtypes/dtypes.py

+3
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,9 @@ def __eq__(self, other: Any) -> bool:
907907

908908
return isinstance(other, PeriodDtype) and self.freq == other.freq
909909

910+
def __ne__(self, other: Any) -> bool:
911+
return not self.__eq__(other)
912+
910913
def __setstate__(self, state):
911914
# for pickle compat. __getstate__ is defined in the
912915
# PandasExtensionDtype superclass and uses the public properties to

pandas/tests/dtypes/test_dtypes.py

+7
Original file line numberDiff line numberDiff line change
@@ -991,3 +991,10 @@ def test_is_dtype_no_warning(check):
991991

992992
with tm.assert_produces_warning(None):
993993
check(data["A"])
994+
995+
996+
def test_period_dtype_compare_to_string():
997+
# https://github.com/pandas-dev/pandas/issues/37265
998+
dtype = PeriodDtype(freq="M")
999+
assert (dtype == "period[M]") is True
1000+
assert (dtype != "period[M]") is False

0 commit comments

Comments
 (0)