You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DOC: Inconsistencies in converting array with datetime values into object array #19782
For reference: the scalar type returned by datetime64.item() (or astype("O") in your case) depends on the unit, though I'm not sure if this actually documented somewhere?
Is there a reason behind this behavior? Where can I find it?
I'm afraid this was a bit before my time; I'm not familiar with the exact rationale here (though admitetly I'm not a huge fan of the practice).
This is annoying especially when using pd.Series, since when calling values in a series it returns by default an array with type datetime64[ns]:
This does sounds like more of a pandas problem though. Numpy itself won't automatically construct a datetime64 array from a datetime.datetime instance, instead returning an object array. The decision to automatically create a datetime64[ns] array is one that is made by pandas.
In [1]: importnumpyasnp
...: importdatetimeasdtIn [2]: np.array(dt.datetime.now()).dtypeOut[2]: dtype('O')
changed the title [-]Inconsistencies when converting array with `datetime` values into object array[/-][+]DOC: Inconsistencies in converting array with `datetime` values into object array[/+]on Aug 24, 2022
Activity
Navaneethan2503 commentedon Aug 30, 2021
There is no inconsistent Found , all works good .
BvB93 commentedon Aug 30, 2021
For reference: the scalar type returned by
datetime64.item()(orastype("O")in your case) depends on the unit, though I'm not sure if this actually documented somewhere?hec10r commentedon Aug 30, 2021
Hi @BvB93 , thanks for answering.
Is there a reason behind this behavior? Where can I find it?
This is annoying especially when using
pd.Series, since when callingvaluesin a series it returns by default an array with typedatetime64[ns]:Is this desired/expected?
BvB93 commentedon Aug 31, 2021
I'm afraid this was a bit before my time; I'm not familiar with the exact rationale here (though admitetly I'm not a huge fan of the practice).
This does sounds like more of a pandas problem though. Numpy itself won't automatically construct a
datetime64array from adatetime.datetimeinstance, instead returning an object array. The decision to automatically create adatetime64[ns]array is one that is made by pandas.hec10r commentedon Aug 31, 2021
I agree, I'm gonna left the issue open because I would like to see the docs/explanation on the first behavior that's not intuitive.
Besides that, everything else makes sense. Thank you @BvB93 !
charris commentedon Aug 31, 2021
I believe Pandas settled on
np.datetime64[ns]as their standard time.MrinaliniTh commentedon Sep 20, 2021
I am fixing this issue as a part of Pycon India conference
[-]Inconsistencies when converting array with `datetime` values into object array[/-][+]DOC: Inconsistencies in converting array with `datetime` values into object array[/+]pojaghi commentedon Sep 16, 2022
I am gonna work on this issue.