What is the proper method to compare the date portion of two numpy.datetime64's?
A: 2011-01-10 Type: <type 'numpy.datetime64'>
B: 2011-01-10T09:00:00.000000-0700 Type: <type 'numpy.datetime64'>
The above example would return false by comparing (A == B)
You'll want to strip your datetime64 of time information before comparison by specifying the 'datetime64[D]' data type, like this:
>>> a = numpy.datetime64('2011-01-10')
>>> b = numpy.datetime64('2011-01-10T09:00:00.000000-0700')
>>> a == b
False
>>> a.astype('datetime64[D]') == b.astype('datetime64[D]')
True
I couldn't get numpy to create an array of datetime64[D]
values from the string you gave for b
above, by the way. I got this error:
>>> b = numpy.array(['2011-01-10T09:00:00.000000-0700'], dtype='datetime64[D]')
TypeError: Cannot parse "2011-01-10T09:00:00.000000-0700" as unit 'D' using casting rule 'same_kind'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With