20
20
import pytz
21
21
22
22
from pandas ._libs .interval import Interval
23
- from pandas ._libs .tslibs import NaT , Period , Timestamp , timezones , to_offset
23
+ from pandas ._libs .tslibs import NaT , Period , Timestamp , dtypes , timezones , to_offset
24
24
from pandas ._libs .tslibs .offsets import BaseOffset
25
25
from pandas ._typing import DtypeObj , Ordered
26
26
@@ -848,7 +848,7 @@ def __setstate__(self, state) -> None:
848
848
849
849
850
850
@register_extension_dtype
851
- class PeriodDtype (PandasExtensionDtype ):
851
+ class PeriodDtype (dtypes . PeriodDtypeBase , PandasExtensionDtype ):
852
852
"""
853
853
An ExtensionDtype for Period data.
854
854
@@ -896,7 +896,8 @@ def __new__(cls, freq=None):
896
896
897
897
elif freq is None :
898
898
# empty constructor for pickle compat
899
- u = object .__new__ (cls )
899
+ # -10_000 corresponds to PeriodDtypeCode.UNDEFINED
900
+ u = dtypes .PeriodDtypeBase .__new__ (cls , - 10_000 )
900
901
u ._freq = None
901
902
return u
902
903
@@ -906,11 +907,15 @@ def __new__(cls, freq=None):
906
907
try :
907
908
return cls ._cache [freq .freqstr ]
908
909
except KeyError :
909
- u = object .__new__ (cls )
910
+ dtype_code = freq ._period_dtype_code
911
+ u = dtypes .PeriodDtypeBase .__new__ (cls , dtype_code )
910
912
u ._freq = freq
911
913
cls ._cache [freq .freqstr ] = u
912
914
return u
913
915
916
+ def __reduce__ (self ):
917
+ return type (self ), (self .freq ,)
918
+
914
919
@property
915
920
def freq (self ):
916
921
"""
@@ -977,7 +982,7 @@ def __eq__(self, other: Any) -> bool:
977
982
return isinstance (other , PeriodDtype ) and self .freq == other .freq
978
983
979
984
def __setstate__ (self , state ):
980
- # for pickle compat. __get_state__ is defined in the
985
+ # for pickle compat. __getstate__ is defined in the
981
986
# PandasExtensionDtype superclass and uses the public properties to
982
987
# pickle -> need to set the settable private ones here (see GH26067)
983
988
self ._freq = state ["freq" ]
0 commit comments