-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: DTA/TDA/PA/Series/Index.view with datetimelike #39788
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 4 commits
9135c4b
e544be2
c216c7b
6147eb7
46ea1a1
c643e9c
b545d41
8d0fa8e
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 |
---|---|---|
|
@@ -793,6 +793,23 @@ def view(self, cls=None): | |
# we need to see if we are subclassing an | ||
# index type here | ||
if cls is not None and not hasattr(cls, "_typ"): | ||
dtype = cls | ||
if isinstance(cls, str): | ||
dtype = pandas_dtype(cls) | ||
|
||
if isinstance(dtype, (np.dtype, ExtensionDtype)) and needs_i8_conversion( | ||
dtype | ||
): | ||
if dtype.kind == "m" and dtype != "m8[ns]": | ||
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. you can handle all m and M types via this branch? 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. L757-L759 is for non-nano td64. L754-L765 handles all td64, dt64, dt64tz, and perioddtype 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 this could use a little more commentary here (similar to what you did on the datetimelike astype), pls catch in a followon |
||
# e.g. m8[s] | ||
return self._data.view(cls) | ||
|
||
arr = self._data.view("i8") | ||
idx_cls = self._dtype_to_subclass(dtype) | ||
arr_cls = idx_cls._data_cls | ||
arr = arr_cls._simple_new(self._data.view("i8"), dtype=dtype) | ||
return idx_cls._simple_new(arr, name=self.name) | ||
|
||
result = self._data.view(cls) | ||
else: | ||
result = self._view() | ||
|
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 think make this clear that M8[ns] (or really M8[s]) or whatever will hit here, but a tz-aware / pandas dtype will pass thru. yes after i read it i get it, but in 3 months no-one will remember.
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.
fleshing out the comment bc its pretty weird. this line isnt catching np.dtype, its catching type, e.g. we get here with
dtype=np.ndarray
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.
updated + green