Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
BUG: to_json not serializing non-nanosecond numpy dt64 correctly #53757
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
BUG: to_json not serializing non-nanosecond numpy dt64 correctly #53757
Changes from 3 commits
e648188
4136ce1
c0e745d
4759340
13ddc60
b45657b
190f43a
cb08985
71fadf5
d95e7cf
f861b6a
c3299de
c9da070
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Is the idea here that this should default to NS for things that are stored within object arrays?
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.
It's for the other stuff like timedeltas and dates. We use nanosecond reso there.
I didn't try to fix those cases as well.
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.
What do you think it would take to handle those consistently? I don't know how common this would happen but I guess its strange to only do this for numpy-typed arrays and not object arrays that may contain datetimes
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.
knee-jerk i think that for object-dtype we should just call
str(x)
on everything and call it a dayThere 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.
The object stuff definitely adds a lot of complexity that may not be worth it, but that would be a breaking change to just pass as a str. Particularly for nested containers within an object array that would not work
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 it might work for object arrays, already.
I haven't checked yet, I'm not on the right branch. Will update later in the day.
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.
Well, it turns out that this didn't work already. Sorry for the confusion.
I've fixed this in the latest commit.
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 part is probably the most sketchy part of this PR.
We currently do this the exact same way numpy does it, but not sure if this is part of the public numpy C API.
FWIW,
PyArray_DatetimeDTypeMetaData
appears inndarraytypes.h
.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.
It would be better if we stuck to a method exposed in the datetime header. Does
get_datetime_metadata_from_dtype
not help here?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.
It would be nice to use that, not sure if that's public either (it's defined inmultiarray/_datetime.h
).Like
PyArray_DatetimeDTypeMetaData
, it also seems to be undocumented. Maybe one of the numpy maintainers(@seberg?) can clarify more?EDIT: NVM, didn't see we had this internally. Sorry for the ping.