2020import pytz
2121
2222from 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
2424from pandas ._libs .tslibs .offsets import BaseOffset
2525from pandas ._typing import DtypeObj , Ordered
2626
@@ -848,7 +848,7 @@ def __setstate__(self, state) -> None:
848848
849849
850850@register_extension_dtype
851- class PeriodDtype (PandasExtensionDtype ):
851+ class PeriodDtype (dtypes . PeriodDtypeBase , PandasExtensionDtype ):
852852 """
853853 An ExtensionDtype for Period data.
854854
@@ -896,7 +896,8 @@ def __new__(cls, freq=None):
896896
897897 elif freq is None :
898898 # 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 )
900901 u ._freq = None
901902 return u
902903
@@ -906,11 +907,15 @@ def __new__(cls, freq=None):
906907 try :
907908 return cls ._cache [freq .freqstr ]
908909 except KeyError :
909- u = object .__new__ (cls )
910+ dtype_code = freq ._period_dtype_code
911+ u = dtypes .PeriodDtypeBase .__new__ (cls , dtype_code )
910912 u ._freq = freq
911913 cls ._cache [freq .freqstr ] = u
912914 return u
913915
916+ def __reduce__ (self ):
917+ return type (self ), (self .freq ,)
918+
914919 @property
915920 def freq (self ):
916921 """
@@ -977,7 +982,7 @@ def __eq__(self, other: Any) -> bool:
977982 return isinstance (other , PeriodDtype ) and self .freq == other .freq
978983
979984 def __setstate__ (self , state ):
980- # for pickle compat. __get_state__ is defined in the
985+ # for pickle compat. __getstate__ is defined in the
981986 # PandasExtensionDtype superclass and uses the public properties to
982987 # pickle -> need to set the settable private ones here (see GH26067)
983988 self ._freq = state ["freq" ]
0 commit comments