-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Update type for PeriodDtype / DatetimeTZDtype / IntervalDtype #22938
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 3 commits
99bafdd
8a8bdb0
f07ab80
83db05c
598cc62
d7a8e1b
e5c61fc
d65980e
bccfc3f
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 |
---|---|---|
|
@@ -4,12 +4,13 @@ | |
from pandas.compat import (string_types, text_type, binary_type, | ||
PY3, PY36) | ||
from pandas._libs import algos, lib | ||
from pandas._libs.tslibs import conversion | ||
from pandas._libs.tslibs import conversion, Period | ||
from pandas._libs.interval import Interval | ||
|
||
from pandas.core.dtypes.dtypes import ( | ||
registry, CategoricalDtype, CategoricalDtypeType, DatetimeTZDtype, | ||
DatetimeTZDtypeType, PeriodDtype, PeriodDtypeType, IntervalDtype, | ||
IntervalDtypeType, PandasExtensionDtype, ExtensionDtype, | ||
DatetimeTZDtypeType, PeriodDtype, IntervalDtype, | ||
PandasExtensionDtype, ExtensionDtype, | ||
_pandas_registry) | ||
from pandas.core.dtypes.generic import ( | ||
ABCCategorical, ABCPeriodIndex, ABCDatetimeIndex, ABCSeries, | ||
|
@@ -1907,18 +1908,18 @@ def _get_dtype_type(arr_or_dtype): | |
elif isinstance(arr_or_dtype, DatetimeTZDtype): | ||
return DatetimeTZDtypeType | ||
elif isinstance(arr_or_dtype, IntervalDtype): | ||
return IntervalDtypeType | ||
return Interval | ||
elif isinstance(arr_or_dtype, PeriodDtype): | ||
return PeriodDtypeType | ||
return Period | ||
elif isinstance(arr_or_dtype, string_types): | ||
if is_categorical_dtype(arr_or_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. what was rationale for not making this object for Categorical here? otherwise this is the odd man out 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 don't recall the previous discussion, but: categorical can basically be everything (so object would still be generic, that is true), but In principle we could pass through the Since the type is actually never used (for the extension dtypes), I would also not bother too much about this one inconsistency. 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. Joris is correct. The only additional comment is that having 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. so why don't we return None then? I think it is going to be very confusing that only Categorical as a DtypeType, but nothing else does. If you are getting rid of it, then remove it completely. 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. None has the same drawbacks of object (cannot be called, is overly generic, does not hold any useful information). The CategoricalDtypeType at least has in its name it is the type of the CategoricalDtype 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. Agreed with Joris. 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. ok, then |
||
return CategoricalDtypeType | ||
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. same here |
||
elif is_datetime64tz_dtype(arr_or_dtype): | ||
return DatetimeTZDtypeType | ||
elif is_period_dtype(arr_or_dtype): | ||
return PeriodDtypeType | ||
return Period | ||
elif is_interval_dtype(arr_or_dtype): | ||
return IntervalDtypeType | ||
return Interval | ||
return _get_dtype_type(np.dtype(arr_or_dtype)) | ||
try: | ||
return arr_or_dtype.dtype.type | ||
|
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.
this is really changing the semantics
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.
Which semantics?
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.
all the other dtypes return the meta class
now you are returning the actual class (and not even the type)
this is not right
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.
This is what we have been doing for all EAs.
Now in practice, I don't if we ever rely on the value, though?
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.
I agree that am not sure this is actually used. But If you are chaning, try changing for all the dtypes? (or don't change). that's what I mean by semantics, we neeed to be consistent.
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.
From the ExtensionArray docs
Period is the scalar type for arrays with PeriodDtype, in the sense that
isinstance(periodarray[0], Period)
is true. What's the issue?Classes are types (they can be used as the second argument to isinstance).
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.
We discussed earlier change CategoricalDtype.type to be object, but IIRC that was rejected (I don't recall the specifics).
Happy to change
DatetimeTZDtypeType
(toTimestamp
).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 see if we have tests that hit any of this? (if not pls add). happy to change to either way, but should just change all.
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.
tests/dtypes/test_common.py::test__get_dtype_type hits this. Otherwise, the only path to here seems to be
_get_dtype_or_type
.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.
And even then, for EA's it is actually never used in
_get_dtype_or_type
(I mean, there is no check function relying on that value, only for numpy dtypes)