@@ -862,6 +862,7 @@ class PeriodDtype(PeriodDtypeBase, PandasExtensionDtype):
862
862
_metadata = ("freq" ,)
863
863
_match = re .compile (r"(P|p)eriod\[(?P<freq>.+)\]" )
864
864
_cache_dtypes : dict [str_type , PandasExtensionDtype ] = {}
865
+ __hash__ = PeriodDtypeBase .__hash__
865
866
866
867
def __new__ (cls , freq ):
867
868
"""
@@ -879,7 +880,7 @@ def __new__(cls, freq):
879
880
return cls ._cache_dtypes [freq .freqstr ]
880
881
except KeyError :
881
882
dtype_code = freq ._period_dtype_code
882
- u = PeriodDtypeBase .__new__ (cls , dtype_code )
883
+ u = PeriodDtypeBase .__new__ (cls , dtype_code , freq . n )
883
884
u ._freq = freq
884
885
cls ._cache_dtypes [freq .freqstr ] = u
885
886
return u
@@ -945,22 +946,11 @@ def name(self) -> str_type:
945
946
def na_value (self ) -> NaTType :
946
947
return NaT
947
948
948
- def __hash__ (self ) -> int :
949
- # make myself hashable
950
- return hash (str (self ))
951
-
952
949
def __eq__ (self , other : Any ) -> bool :
953
950
if isinstance (other , str ):
954
951
return other in [self .name , self .name .title ()]
955
952
956
- elif isinstance (other , PeriodDtype ):
957
- # For freqs that can be held by a PeriodDtype, this check is
958
- # equivalent to (and much faster than) self.freq == other.freq
959
- sfreq = self ._freq
960
- ofreq = other ._freq
961
- return sfreq .n == ofreq .n and self ._dtype_code == other ._dtype_code
962
-
963
- return False
953
+ return super ().__eq__ (other )
964
954
965
955
def __ne__ (self , other : Any ) -> bool :
966
956
return not self .__eq__ (other )
0 commit comments