[Numpy-discussion] Dates and times and Datetime64 (again)
shoyer at gmail.com
Fri Apr 11 19:58:22 EDT 2014
On Fri, Apr 11, 2014 at 3:56 PM, Charles R Harris <charlesr.harris at gmail.com
> Are we in a position to start looking at implementation? If so, it would
> be useful to have a collection of test cases, i.e., typical uses with
> specified results. That should also cover conversion from/(to?)
Indeed, my personal wish-list for np.datetime64 is centered much more on
robust conversion to/from native date objects, including comparison.
Here are some of my particular points of frustration (apologies for the
- NaT should have similar behavior to NaN when used for comparisons (i.e.,
comparisons should always be False).
- You can't compare a datetime object to a datetime64 object.
- datetime64 objects with high precision (e.g., ns) can't compare to
Pandas has a very nice wrapper around datetime64 arrays that solves most of
these issues, but it would be nice to get much of that functionality in
core numpy, since I don't always want to store my values in a 1-dimensional
array + hash-table (the pandas Index):
Here's code which reproduces all of the above:
from numpy import datetime64
from datetime import datetime
print np.datetime64('NaT') < np.datetime64('2011-01-01') # this should not
print datetime(2010, 1, 1) < np.datetime64('2011-01-01') # raises exception
print np.datetime64('2011-01-01T00:00', 'ns') > datetime(2010, 1, 1) #
print np.datetime64('2011-01-01T00:00') > datetime(2010, 1, 1) # finally
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion