[Numpy-discussion] Dates and times and Datetime64 (again)

Chris Barker chris.barker at noaa.gov
Mon Apr 28 13:40:49 EDT 2014


On Fri, Apr 25, 2014 at 4:57 AM, Andreas Hilboll <lists at hilboll.de> wrote:

> Array-wide access to the individual datetime components should work, i.e.,
>

>    datetime64array.year
>
> should yield an array of dtype int with the years.  That would allow
> boolean indexing to filter data, like
>
>    datetime64array[datetime64array.year == 2014]
>
> would yield all entries from 2014.
>

that would be nice, yes, but datetime64 doesn't support anything like that
at all -- i.e. array-wide or not access to the components. In this case,
you could kludge it with:

In [19]: datetimearray
Out[19]: array(['2014-02-03', '2013-03-08', '2012-03-07', '2014-04-06'],
dtype='datetime64[D]')

In [20]: datetimearray[datetimearray.astype('datetime64[Y]') ==
np.datetime64('2014')]
Out[20]: array(['2014-02-03', '2014-04-06'], dtype='datetime64[D]')

but that wouldn't work for months, for instance.

I think the current NEP should stick with simply fixing the timezone thing
-- no new functionality or consequence.

But:

Maybe it's time for a new NEP for what we want datetime64 to be in the
future -- maybe borrow from the blaze proposal cited earlier? Or wait and
see how that works out, then maybe port that code over to numpy?

In the meantime, a set of utilities that do the kind of things you're
looking for might make sense. You could do it as a ndarray subclass, and
add those sorts of methods, though ndarray subclasses do get messy....

-Chris




-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140428/af839d7d/attachment.html>


More information about the NumPy-Discussion mailing list