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
Converting ns/as-precision datetime64 to datetime.datetime results in integer #8546
This is painful because xarray (and pandas, I believe) internally uses nanosecond-precision, which means those cannot be correctly converted to datetime.datetime objects.
changed the title [-]Converting µs/as-precisiong datetime64 to datetime.datetime results in integer[/-][+]Converting ns/as-precision datetime64 to datetime.datetime results in integer[/+]on Jan 30, 2017
More direct illustration: timedelta64(100, 'ns').item() → 100. I understand that datetime.datetime is unable to represent this but I'm not convinced this is the best approach.
timedelta64(100, 'ns').item() == datetime.timedelta(0) and np.float128(tiny).item() == 0.0, both emitting warnings about loss of precision due to casting to object / calling item()
Split up the astype(object) / item() concerns, and have .astype(object) always leave numpy scalars intact.
Activity
gerritholl commentedon Jan 30, 2017
This is painful because xarray (and pandas, I believe) internally uses nanosecond-precision, which means those cannot be correctly converted to
datetime.datetimeobjects.[-]Converting µs/as-precisiong datetime64 to datetime.datetime results in integer[/-][+]Converting ns/as-precision datetime64 to datetime.datetime results in integer[/+]gerritholl commentedon Jan 30, 2017
More direct illustration:
timedelta64(100, 'ns').item()→100. I understand thatdatetime.datetimeis unable to represent this but I'm not convinced this is the best approach.shoyer commentedon Jan 30, 2017
This is basically the same issue as #7619 and #4337
eric-wieser commentedon Oct 18, 2017
It seems to me that the best approach here is either:
timedelta64(100, 'ns').item() == timedelta64(100, 'ns')is which at least is consistent with float128(0).item() returns numpy.float128 #8547timedelta64(100, 'ns').item() == datetime.timedelta(0)andnp.float128(tiny).item() == 0.0, both emitting warnings about loss of precision due to casting toobject/ callingitem()astype(object)/item()concerns, and have.astype(object)always leave numpy scalars intact.eric-wieser commentedon Feb 18, 2019
Closing as a duplicate of #12550, since there's far more discussion there