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
convert datetime64 from/to vectorized dates #4824
Comments
This page is for bugs and feature requests to Numpy, consider posting this question at Stackoverlow |
This indeed was a bug report: both about documentation and methods available for datetime64. The documentation focuses on initialization of datetime64 from list of strings. This is irrelevant for huge time rows.
Thanks you very much for considering these bug / enhancement reports. |
Sorry to be pedantic, but this is now a bug/"documentation request", the first text was not. ad 1) I fully agree with you that the docs are lacking usage examples like conversion from other formats like the one you present. import numpy as np
olddtype = np.dtype([('YY', '<i4'), ('MM', '<i4'), ('DD', '<i4'), ('hh', '<i4'), ('mm', '<i4'), ('ss', '<f8')])
d = np.array([(2014, 12, 24, 12, 00, 45),
(2012, 2, 14, 23, 29, 52),
(2013, 10, 4, 8, 49, 21)], dtype=olddtype)
d1 = d.astype(np.dtype([('YY', 'datetime64[Y]'), ('MM', 'timedelta64[M]'), ('DD', 'timedelta64[D]'), ('hh', 'timedelta64[h]'), ('mm', 'timedelta64[m]'), ('ss', 'timedelta64[s]')]))
d2 = d1['YY']-1971 + d1['MM'] + d1['DD'] + d1['hh'] + d1['mm'] + d1['ss'] |
I agree. I deliberately prefer to submit bad bug/doc report quickly: I would forget if I tried to put it off. Thank you for your explanation. |
In our applications, we often represent datetime as a np.array with dtype
[('YY', '<i4'), ('MM', '<i4'), ('DD', '<i4'), ('hh', '<i4'), ('mm', '<i4'), ('ss', '<f8')]
Can this be converted to datetime64, using vector methods?
Of course, converting to string and reparsing is not an option, it would be awfully slow.
The text was updated successfully, but these errors were encountered: