-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: to_csv casting datetimes in categorical to int #44930
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
Conversation
phofl
commented
Dec 16, 2021
•
edited
Loading
edited
- closes BUG: to_csv produces improper output for categorical datetimes #40754
- closes .astype('object') misbehaves on Categorical containing Timestamp #18024
- tests added / passed
- Ensure all linting tests pass, see here for how to run them
- whatsnew entry
i think the underlying problem is in |
Was not sure if this was intentional in the astype call. Will have a look again |
� Conflicts: � doc/source/whatsnew/v1.4.0.rst
pandas/core/arrays/categorical.py
Outdated
@@ -532,7 +533,12 @@ def astype(self, dtype: AstypeArg, copy: bool = True) -> ArrayLike: | |||
else: | |||
# GH8628 (PERF): astype category codes instead of astyping array | |||
try: | |||
new_cats = np.asarray(self.categories) | |||
if is_datetime64_dtype(self.categories): | |||
values = ensure_wrapped_if_datetimelike(np.asarray(self.categories)) |
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.
self.categories._values
should be what you want here. thats probably also an improvement if is_datetime64tz_dtype(self.categories.dtype)
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.
tz aware datetimes are alreday handled correctly
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 was thinking it might be a perf improvement for dt64tz, but either way its fine to consider that out of scope for this PR
So I think I figured the issue out now.
|
thanks @phofl |