-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
DOC: better document Dtypes docstrings + avoid sphinx warnings #26067
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
acc47b9
e79d793
6620d84
44b8d09
8818681
f61ebc0
d43ee0f
82e53a5
84baf36
c8ae0c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -169,7 +169,7 @@ class CategoricalDtypeType(type): | |||||||
@register_extension_dtype | ||||||||
class CategoricalDtype(PandasExtensionDtype, ExtensionDtype): | ||||||||
""" | ||||||||
Type for categorical data with the categories and orderedness | ||||||||
Type for categorical data with the categories and orderedness. | ||||||||
|
||||||||
.. versionchanged:: 0.21.0 | ||||||||
|
||||||||
|
@@ -334,6 +334,9 @@ def _finalize(self, categories, ordered, fastpath=False): | |||||||
self._ordered = ordered | ||||||||
|
||||||||
def __setstate__(self, state): | ||||||||
# for pickle compat. __get_state__ is defined in the | ||||||||
# PandasExtensionDtype superclass and uses the public properties to | ||||||||
# pickle -> need to set the settable private ones here (see GH26067) | ||||||||
self._categories = state.pop('categories', None) | ||||||||
self._ordered = state.pop('ordered', False) | ||||||||
|
||||||||
|
@@ -570,13 +573,40 @@ def _is_boolean(self): | |||||||
|
||||||||
@register_extension_dtype | ||||||||
class DatetimeTZDtype(PandasExtensionDtype, ExtensionDtype): | ||||||||
|
||||||||
""" | ||||||||
A np.dtype duck-typed class, suitable for holding a custom datetime with tz | ||||||||
dtype. | ||||||||
An ExtensionDtype for timezone-aware datetime data. | ||||||||
|
||||||||
**This is not an actual numpy dtype**, but a duck type. | ||||||||
|
||||||||
Parameters | ||||||||
---------- | ||||||||
unit : str, default "ns" | ||||||||
The precision of the datetime data. Currently limited | ||||||||
to ``"ns"``. | ||||||||
tz : str, int, or datetime.tzinfo | ||||||||
The timezone. | ||||||||
|
||||||||
Attributes | ||||||||
---------- | ||||||||
unit | ||||||||
tz | ||||||||
|
||||||||
Methods | ||||||||
------- | ||||||||
None | ||||||||
|
||||||||
THIS IS NOT A REAL NUMPY DTYPE, but essentially a sub-class of | ||||||||
np.datetime64[ns] | ||||||||
Raises | ||||||||
------ | ||||||||
pytz.UnknownTimeZoneError | ||||||||
When the requested timezone cannot be found. | ||||||||
|
||||||||
Examples | ||||||||
-------- | ||||||||
>>> pd.DatetimeTZDtype(tz='UTC') | ||||||||
datetime64[ns, UTC] | ||||||||
|
||||||||
>>> pd.DatetimeTZDtype(tz='dateutil/US/Central') | ||||||||
datetime64[ns, tzfile('/usr/share/zoneinfo/US/Central')] | ||||||||
""" | ||||||||
type = Timestamp # type: Type[Timestamp] | ||||||||
kind = 'M' # type: str_type | ||||||||
|
@@ -589,30 +619,6 @@ class DatetimeTZDtype(PandasExtensionDtype, ExtensionDtype): | |||||||
_cache = {} # type: Dict[str_type, PandasExtensionDtype] | ||||||||
|
||||||||
def __init__(self, unit="ns", tz=None): | ||||||||
""" | ||||||||
An ExtensionDtype for timezone-aware datetime data. | ||||||||
|
||||||||
Parameters | ||||||||
---------- | ||||||||
unit : str, default "ns" | ||||||||
The precision of the datetime data. Currently limited | ||||||||
to ``"ns"``. | ||||||||
tz : str, int, or datetime.tzinfo | ||||||||
The timezone. | ||||||||
|
||||||||
Raises | ||||||||
------ | ||||||||
pytz.UnknownTimeZoneError | ||||||||
When the requested timezone cannot be found. | ||||||||
|
||||||||
Examples | ||||||||
-------- | ||||||||
>>> pd.core.dtypes.dtypes.DatetimeTZDtype(tz='UTC') | ||||||||
datetime64[ns, UTC] | ||||||||
|
||||||||
>>> pd.core.dtypes.dtypes.DatetimeTZDtype(tz='dateutil/US/Central') | ||||||||
datetime64[ns, tzfile('/usr/share/zoneinfo/US/Central')] | ||||||||
""" | ||||||||
if isinstance(unit, DatetimeTZDtype): | ||||||||
unit, tz = unit.unit, unit.tz | ||||||||
|
||||||||
|
@@ -718,17 +724,40 @@ def __eq__(self, other): | |||||||
str(self.tz) == str(other.tz)) | ||||||||
|
||||||||
def __setstate__(self, state): | ||||||||
# for pickle compat. | ||||||||
# for pickle compat. __get_state__ is defined in the | ||||||||
# PandasExtensionDtype superclass and uses the public properties to | ||||||||
# pickle -> need to set the settable private ones here (see GH26067) | ||||||||
self._tz = state['tz'] | ||||||||
self._unit = state['unit'] | ||||||||
|
||||||||
|
||||||||
@register_extension_dtype | ||||||||
class PeriodDtype(ExtensionDtype, PandasExtensionDtype): | ||||||||
""" | ||||||||
A Period duck-typed class, suitable for holding a period with freq dtype. | ||||||||
An ExtensionDtype for Period data. | ||||||||
|
||||||||
**This is not an actual numpy dtype**, but a duck type. | ||||||||
|
||||||||
Parameters | ||||||||
---------- | ||||||||
freq : str or DateOffset | ||||||||
The frequency of this PeriodDtype | ||||||||
|
||||||||
Attributes | ||||||||
---------- | ||||||||
freq | ||||||||
|
||||||||
THIS IS NOT A REAL NUMPY DTYPE, but essentially a sub-class of np.int64. | ||||||||
Methods | ||||||||
------- | ||||||||
None | ||||||||
|
||||||||
Examples | ||||||||
-------- | ||||||||
>>> pd.PeriodDtype(freq='D') | ||||||||
period[D] | ||||||||
|
||||||||
>>> pd.PeriodDtype(freq=pd.offsets.MonthEnd()) | ||||||||
period[M] | ||||||||
""" | ||||||||
type = Period # type: Type[Period] | ||||||||
kind = 'O' # type: str_type | ||||||||
|
@@ -751,7 +780,9 @@ def __new__(cls, freq=None): | |||||||
|
||||||||
elif freq is None: | ||||||||
# empty constructor for pickle compat | ||||||||
return object.__new__(cls) | ||||||||
u = object.__new__(cls) | ||||||||
u._freq = None | ||||||||
return u | ||||||||
|
||||||||
if not isinstance(freq, ABCDateOffset): | ||||||||
freq = cls._parse_dtype_strict(freq) | ||||||||
|
@@ -760,10 +791,15 @@ def __new__(cls, freq=None): | |||||||
return cls._cache[freq.freqstr] | ||||||||
except KeyError: | ||||||||
u = object.__new__(cls) | ||||||||
u.freq = freq | ||||||||
u._freq = freq | ||||||||
cls._cache[freq.freqstr] = u | ||||||||
return u | ||||||||
|
||||||||
@property | ||||||||
def freq(self): | ||||||||
"""The frequency object of this PeriodDtype.""" | ||||||||
return self._freq | ||||||||
|
||||||||
@classmethod | ||||||||
def _parse_dtype_strict(cls, freq): | ||||||||
if isinstance(freq, str): | ||||||||
|
@@ -817,6 +853,12 @@ def __eq__(self, other): | |||||||
|
||||||||
return isinstance(other, PeriodDtype) and self.freq == other.freq | ||||||||
|
||||||||
def __setstate__(self, state): | ||||||||
# for pickle compat. __get_state__ is defined in the | ||||||||
# PandasExtensionDtype superclass and uses the public properties to | ||||||||
# pickle -> need to set the settable private ones here (see GH26067) | ||||||||
self._freq = state['freq'] | ||||||||
|
||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we have a round-trip on this test? shouldn't you also need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
pandas/pandas/core/dtypes/dtypes.py Lines 152 to 154 in 455a2cd
Added in 154a647 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And it's the round trip test that was failing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, what if you move There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I have been thinking about that as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, yeah they are coupled. i don't really like having to be explicit about the pickle compat here..... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yep, I agree. Although it is consistent with how it is already done in the other dtypes (Categorical actually has the same), it would be nice to clean it up. I could also add a different |
||||||||
@classmethod | ||||||||
def is_dtype(cls, dtype): | ||||||||
""" | ||||||||
|
@@ -849,9 +891,27 @@ def construct_array_type(cls): | |||||||
@register_extension_dtype | ||||||||
class IntervalDtype(PandasExtensionDtype, ExtensionDtype): | ||||||||
""" | ||||||||
A Interval duck-typed class, suitable for holding an interval | ||||||||
An ExtensionDtype for Interval data. | ||||||||
|
||||||||
THIS IS NOT A REAL NUMPY DTYPE | ||||||||
**This is not an actual numpy dtype**, but a duck type. | ||||||||
|
||||||||
Parameters | ||||||||
---------- | ||||||||
subtype : str, np.dtype | ||||||||
The dtype of the Interval bounds. | ||||||||
|
||||||||
Attributes | ||||||||
---------- | ||||||||
subtype | ||||||||
|
||||||||
Methods | ||||||||
------- | ||||||||
None | ||||||||
|
||||||||
Examples | ||||||||
-------- | ||||||||
>>> pd.IntervalDtype(subtype='int64') | ||||||||
interval[int64] | ||||||||
""" | ||||||||
name = 'interval' | ||||||||
kind = None # type: Optional[str_type] | ||||||||
|
@@ -863,11 +923,6 @@ class IntervalDtype(PandasExtensionDtype, ExtensionDtype): | |||||||
_cache = {} # type: Dict[str_type, PandasExtensionDtype] | ||||||||
|
||||||||
def __new__(cls, subtype=None): | ||||||||
""" | ||||||||
Parameters | ||||||||
---------- | ||||||||
subtype : the dtype of the Interval | ||||||||
""" | ||||||||
from pandas.core.dtypes.common import ( | ||||||||
is_categorical_dtype, is_string_dtype, pandas_dtype) | ||||||||
|
||||||||
|
@@ -877,7 +932,7 @@ def __new__(cls, subtype=None): | |||||||
# we are called as an empty constructor | ||||||||
# generally for pickle compat | ||||||||
u = object.__new__(cls) | ||||||||
u.subtype = None | ||||||||
u._subtype = None | ||||||||
return u | ||||||||
elif (isinstance(subtype, str) and | ||||||||
subtype.lower() == 'interval'): | ||||||||
|
@@ -903,10 +958,15 @@ def __new__(cls, subtype=None): | |||||||
return cls._cache[str(subtype)] | ||||||||
except KeyError: | ||||||||
u = object.__new__(cls) | ||||||||
u.subtype = subtype | ||||||||
u._subtype = subtype | ||||||||
cls._cache[str(subtype)] = u | ||||||||
return u | ||||||||
|
||||||||
@property | ||||||||
def subtype(self): | ||||||||
"""The dtype of the Interval bounds.""" | ||||||||
return self._subtype | ||||||||
|
||||||||
@classmethod | ||||||||
def construct_array_type(cls): | ||||||||
""" | ||||||||
|
@@ -963,6 +1023,12 @@ def __eq__(self, other): | |||||||
from pandas.core.dtypes.common import is_dtype_equal | ||||||||
return is_dtype_equal(self.subtype, other.subtype) | ||||||||
|
||||||||
def __setstate__(self, state): | ||||||||
# for pickle compat. __get_state__ is defined in the | ||||||||
# PandasExtensionDtype superclass and uses the public properties to | ||||||||
# pickle -> need to set the settable private ones here (see GH26067) | ||||||||
self._subtype = state['subtype'] | ||||||||
|
||||||||
@classmethod | ||||||||
def is_dtype(cls, dtype): | ||||||||
""" | ||||||||
|
Uh oh!
There was an error while loading. Please reload this page.