-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
BUG: .item() on a 0-dimensional datetime64[ns] array yields an integer #7619
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
Comments
The behaviour on |
Is there any progress with fixing this issue? |
Another option in addition to the OP: I know this is a large breaking change, but it is still the best behaviour to follow IMO. |
@h-vetinari's suggestion is not a terrible one, and is at least somewhat consistent with how Which of the following does the suggestion apply to?
|
My suggestion applies to all datetime types**. And the ramifications (intentionally) don't stop at ** probably timedeltas too? Actually I tend to think that |
I'm starting to think the answer is "then don't use item". You can get the semantics you want with: def scalar_from(arr):
return arr.squeeze(axis=range(axis.ndim))[()] or if you don't care for the weird semantics we're trying to deprecate in #10615, def scalar_from(arr):
assert arr.ndim == 0
arr[()] |
Fair, but apparently |
That perhaps then is the change to make - changing the meaning of |
This is obviously not useful:
The underlying issue is that not all datetime64 types can be represented in
datetime.datetime
objects, which have fixed us precision.We should either:
TypeError
in all cases when calling.item()
on a datetime64[ns] array.datetime.datetime
if it can be done safely, raiseValueError
otherwise.My preference is for 2.
The text was updated successfully, but these errors were encountered: