@@ -169,7 +169,7 @@ class CategoricalDtypeType(type):
169169@register_extension_dtype
170170class CategoricalDtype (PandasExtensionDtype , ExtensionDtype ):
171171 """
172- Type for categorical data with the categories and orderedness
172+ Type for categorical data with the categories and orderedness.
173173
174174 .. versionchanged:: 0.21.0
175175
@@ -334,6 +334,9 @@ def _finalize(self, categories, ordered, fastpath=False):
334334 self ._ordered = ordered
335335
336336 def __setstate__ (self , state ):
337+ # for pickle compat. __get_state__ is defined in the
338+ # PandasExtensionDtype superclass and uses the public properties to
339+ # pickle -> need to set the settable private ones here (see GH26067)
337340 self ._categories = state .pop ('categories' , None )
338341 self ._ordered = state .pop ('ordered' , False )
339342
@@ -570,13 +573,40 @@ def _is_boolean(self):
570573
571574@register_extension_dtype
572575class DatetimeTZDtype (PandasExtensionDtype , ExtensionDtype ):
573-
574576 """
575- A np.dtype duck-typed class, suitable for holding a custom datetime with tz
576- dtype.
577+ An ExtensionDtype for timezone-aware datetime data.
578+
579+ **This is not an actual numpy dtype**, but a duck type.
580+
581+ Parameters
582+ ----------
583+ unit : str, default "ns"
584+ The precision of the datetime data. Currently limited
585+ to ``"ns"``.
586+ tz : str, int, or datetime.tzinfo
587+ The timezone.
588+
589+ Attributes
590+ ----------
591+ unit
592+ tz
593+
594+ Methods
595+ -------
596+ None
577597
578- THIS IS NOT A REAL NUMPY DTYPE, but essentially a sub-class of
579- np.datetime64[ns]
598+ Raises
599+ ------
600+ pytz.UnknownTimeZoneError
601+ When the requested timezone cannot be found.
602+
603+ Examples
604+ --------
605+ >>> pd.DatetimeTZDtype(tz='UTC')
606+ datetime64[ns, UTC]
607+
608+ >>> pd.DatetimeTZDtype(tz='dateutil/US/Central')
609+ datetime64[ns, tzfile('/usr/share/zoneinfo/US/Central')]
580610 """
581611 type = Timestamp # type: Type[Timestamp]
582612 kind = 'M' # type: str_type
@@ -589,30 +619,6 @@ class DatetimeTZDtype(PandasExtensionDtype, ExtensionDtype):
589619 _cache = {} # type: Dict[str_type, PandasExtensionDtype]
590620
591621 def __init__ (self , unit = "ns" , tz = None ):
592- """
593- An ExtensionDtype for timezone-aware datetime data.
594-
595- Parameters
596- ----------
597- unit : str, default "ns"
598- The precision of the datetime data. Currently limited
599- to ``"ns"``.
600- tz : str, int, or datetime.tzinfo
601- The timezone.
602-
603- Raises
604- ------
605- pytz.UnknownTimeZoneError
606- When the requested timezone cannot be found.
607-
608- Examples
609- --------
610- >>> pd.core.dtypes.dtypes.DatetimeTZDtype(tz='UTC')
611- datetime64[ns, UTC]
612-
613- >>> pd.core.dtypes.dtypes.DatetimeTZDtype(tz='dateutil/US/Central')
614- datetime64[ns, tzfile('/usr/share/zoneinfo/US/Central')]
615- """
616622 if isinstance (unit , DatetimeTZDtype ):
617623 unit , tz = unit .unit , unit .tz
618624
@@ -718,17 +724,40 @@ def __eq__(self, other):
718724 str (self .tz ) == str (other .tz ))
719725
720726 def __setstate__ (self , state ):
721- # for pickle compat.
727+ # for pickle compat. __get_state__ is defined in the
728+ # PandasExtensionDtype superclass and uses the public properties to
729+ # pickle -> need to set the settable private ones here (see GH26067)
722730 self ._tz = state ['tz' ]
723731 self ._unit = state ['unit' ]
724732
725733
726734@register_extension_dtype
727735class PeriodDtype (ExtensionDtype , PandasExtensionDtype ):
728736 """
729- A Period duck-typed class, suitable for holding a period with freq dtype.
737+ An ExtensionDtype for Period data.
738+
739+ **This is not an actual numpy dtype**, but a duck type.
740+
741+ Parameters
742+ ----------
743+ freq : str or DateOffset
744+ The frequency of this PeriodDtype
745+
746+ Attributes
747+ ----------
748+ freq
730749
731- THIS IS NOT A REAL NUMPY DTYPE, but essentially a sub-class of np.int64.
750+ Methods
751+ -------
752+ None
753+
754+ Examples
755+ --------
756+ >>> pd.PeriodDtype(freq='D')
757+ period[D]
758+
759+ >>> pd.PeriodDtype(freq=pd.offsets.MonthEnd())
760+ period[M]
732761 """
733762 type = Period # type: Type[Period]
734763 kind = 'O' # type: str_type
@@ -751,7 +780,9 @@ def __new__(cls, freq=None):
751780
752781 elif freq is None :
753782 # empty constructor for pickle compat
754- return object .__new__ (cls )
783+ u = object .__new__ (cls )
784+ u ._freq = None
785+ return u
755786
756787 if not isinstance (freq , ABCDateOffset ):
757788 freq = cls ._parse_dtype_strict (freq )
@@ -760,10 +791,15 @@ def __new__(cls, freq=None):
760791 return cls ._cache [freq .freqstr ]
761792 except KeyError :
762793 u = object .__new__ (cls )
763- u .freq = freq
794+ u ._freq = freq
764795 cls ._cache [freq .freqstr ] = u
765796 return u
766797
798+ @property
799+ def freq (self ):
800+ """The frequency object of this PeriodDtype."""
801+ return self ._freq
802+
767803 @classmethod
768804 def _parse_dtype_strict (cls , freq ):
769805 if isinstance (freq , str ):
@@ -817,6 +853,12 @@ def __eq__(self, other):
817853
818854 return isinstance (other , PeriodDtype ) and self .freq == other .freq
819855
856+ def __setstate__ (self , state ):
857+ # for pickle compat. __get_state__ is defined in the
858+ # PandasExtensionDtype superclass and uses the public properties to
859+ # pickle -> need to set the settable private ones here (see GH26067)
860+ self ._freq = state ['freq' ]
861+
820862 @classmethod
821863 def is_dtype (cls , dtype ):
822864 """
@@ -849,9 +891,27 @@ def construct_array_type(cls):
849891@register_extension_dtype
850892class IntervalDtype (PandasExtensionDtype , ExtensionDtype ):
851893 """
852- A Interval duck-typed class, suitable for holding an interval
894+ An ExtensionDtype for Interval data.
853895
854- THIS IS NOT A REAL NUMPY DTYPE
896+ **This is not an actual numpy dtype**, but a duck type.
897+
898+ Parameters
899+ ----------
900+ subtype : str, np.dtype
901+ The dtype of the Interval bounds.
902+
903+ Attributes
904+ ----------
905+ subtype
906+
907+ Methods
908+ -------
909+ None
910+
911+ Examples
912+ --------
913+ >>> pd.IntervalDtype(subtype='int64')
914+ interval[int64]
855915 """
856916 name = 'interval'
857917 kind = None # type: Optional[str_type]
@@ -863,11 +923,6 @@ class IntervalDtype(PandasExtensionDtype, ExtensionDtype):
863923 _cache = {} # type: Dict[str_type, PandasExtensionDtype]
864924
865925 def __new__ (cls , subtype = None ):
866- """
867- Parameters
868- ----------
869- subtype : the dtype of the Interval
870- """
871926 from pandas .core .dtypes .common import (
872927 is_categorical_dtype , is_string_dtype , pandas_dtype )
873928
@@ -877,7 +932,7 @@ def __new__(cls, subtype=None):
877932 # we are called as an empty constructor
878933 # generally for pickle compat
879934 u = object .__new__ (cls )
880- u .subtype = None
935+ u ._subtype = None
881936 return u
882937 elif (isinstance (subtype , str ) and
883938 subtype .lower () == 'interval' ):
@@ -903,10 +958,15 @@ def __new__(cls, subtype=None):
903958 return cls ._cache [str (subtype )]
904959 except KeyError :
905960 u = object .__new__ (cls )
906- u .subtype = subtype
961+ u ._subtype = subtype
907962 cls ._cache [str (subtype )] = u
908963 return u
909964
965+ @property
966+ def subtype (self ):
967+ """The dtype of the Interval bounds."""
968+ return self ._subtype
969+
910970 @classmethod
911971 def construct_array_type (cls ):
912972 """
@@ -963,6 +1023,12 @@ def __eq__(self, other):
9631023 from pandas .core .dtypes .common import is_dtype_equal
9641024 return is_dtype_equal (self .subtype , other .subtype )
9651025
1026+ def __setstate__ (self , state ):
1027+ # for pickle compat. __get_state__ is defined in the
1028+ # PandasExtensionDtype superclass and uses the public properties to
1029+ # pickle -> need to set the settable private ones here (see GH26067)
1030+ self ._subtype = state ['subtype' ]
1031+
9661032 @classmethod
9671033 def is_dtype (cls , dtype ):
9681034 """
0 commit comments