-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
WIP: make _holder changeover #24540
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
WIP: make _holder changeover #24540
Changes from 7 commits
0f687c1
d422941
483597b
007b167
5fdb073
63145cd
9b12f98
e76ad68
39436a2
45a4ae7
e50e662
2e6310c
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 |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
is_extension_type, is_float_dtype, is_int64_dtype, is_object_dtype, | ||
is_period_dtype, is_string_dtype, is_timedelta64_dtype, pandas_dtype) | ||
from pandas.core.dtypes.dtypes import DatetimeTZDtype | ||
from pandas.core.dtypes.generic import ABCIndexClass, ABCSeries | ||
from pandas.core.dtypes.generic import ABCIndexClass, ABCSeries, ABCPandasArray | ||
from pandas.core.dtypes.missing import isna | ||
|
||
from pandas.core import ops | ||
|
@@ -240,11 +240,14 @@ def _simple_new(cls, values, freq=None, tz=None): | |
result._dtype = dtype | ||
return result | ||
|
||
def __new__(cls, values, freq=None, tz=None, dtype=None, copy=False, | ||
def __init__(self, values, freq=None, tz=None, dtype=None, copy=False, | ||
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. The init should be |
||
dayfirst=False, yearfirst=False, ambiguous='raise'): | ||
return cls._from_sequence( | ||
result = type(self)._from_sequence( | ||
values, freq=freq, tz=tz, dtype=dtype, copy=copy, | ||
dayfirst=dayfirst, yearfirst=yearfirst, ambiguous=ambiguous) | ||
self._data = result._data | ||
self._freq = result._freq | ||
self._dtype = result._dtype | ||
|
||
@classmethod | ||
def _from_sequence(cls, data, dtype=None, copy=False, | ||
|
@@ -523,7 +526,9 @@ def _ndarray_values(self): | |
|
||
@Appender(dtl.DatetimeLikeArrayMixin._validate_fill_value.__doc__) | ||
def _validate_fill_value(self, fill_value): | ||
if isna(fill_value): | ||
if isna(fill_value) or fill_value == iNaT: | ||
# FIXME: shouldn't allow iNaT through here; see discussion | ||
# in GH#24024 | ||
fill_value = iNaT | ||
elif isinstance(fill_value, (datetime, np.datetime64)): | ||
self._assert_tzawareness_compat(fill_value) | ||
|
@@ -1568,6 +1573,8 @@ def sequence_to_dt64ns(data, dtype=None, copy=False, | |
copy = False | ||
elif isinstance(data, ABCSeries): | ||
data = data._values | ||
elif isinstance(data, ABCPandasArray): | ||
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 you know if this is necessary? Why not fall through to the usual sequence handling? 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. there was a test in tests.series.test_missing that ended up calling lib.infer_dtype and raising an AttributeError because PandasDType doesn't have a 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. That probably indicates a bug that this is hiding. Shouldn't all non ndarray sequences be converted to ndarrays before calling infer_dtype? 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. i seem to recall something about extension dtypes being registered in such a way that infer_dtype could pick up on them. will take a look 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. @jbrockmendel The only ones that are directly implemented are |
||
data = data.to_numpy() | ||
|
||
if hasattr(data, "freq"): | ||
# i.e. DatetimeArray/Index | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -479,8 +479,8 @@ def _is_boolean(self): | |
return is_bool_dtype(self.categories) | ||
|
||
|
||
class DatetimeTZDtype(PandasExtensionDtype): | ||
|
||
@register_extension_dtype | ||
class DatetimeTZDtype(PandasExtensionDtype, ExtensionDtype): | ||
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. I think we can now 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. Good as a followup item I think. IIRC I created an issue when I had to create PandasExtensionDtype in the first place. 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. yes, i agree, do we have an issue about fixing this? |
||
""" | ||
A np.dtype duck-typed class, suitable for holding a custom datetime with tz | ||
dtype. | ||
|
@@ -493,6 +493,7 @@ class DatetimeTZDtype(PandasExtensionDtype): | |
str = '|M8[ns]' | ||
num = 101 | ||
base = np.dtype('M8[ns]') | ||
na_value = NaT | ||
_metadata = ('unit', 'tz') | ||
_match = re.compile(r"(datetime64|M8)\[(?P<unit>.+), (?P<tz>.+)\]") | ||
_cache = {} | ||
|
@@ -570,8 +571,8 @@ def construct_array_type(cls): | |
------- | ||
type | ||
""" | ||
from pandas import DatetimeIndex | ||
return DatetimeIndex | ||
from pandas.core.arrays import DatetimeArrayMixin | ||
return DatetimeArrayMixin | ||
|
||
@classmethod | ||
def construct_from_string(cls, string): | ||
|
@@ -885,10 +886,3 @@ def is_dtype(cls, dtype): | |
else: | ||
return False | ||
return super(IntervalDtype, cls).is_dtype(dtype) | ||
|
||
|
||
# TODO(Extension): remove the second registry once all internal extension | ||
# dtypes are real extension dtypes. | ||
_pandas_registry = Registry() | ||
|
||
_pandas_registry.register(DatetimeTZDtype) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a comment here about what this is doing, and . TODO to see if we can remove the .values below