[Numpy-discussion] code review for datetime arange
Mark Wiebe
mwwiebe at gmail.com
Thu Jun 9 16:58:57 EDT 2011
On Thu, Jun 9, 2011 at 3:41 PM, Christopher Barker <Chris.Barker at noaa.gov>
wrote:
> Mark Wiebe wrote:
> > Because of the nature of datetime and timedelta, arange has to be
> > slightly different than with all the other types. In particular, for
> > datetime the primary signature is np.arange(datetime, datetime,
> timedelta).
> >
> > I've implemented a simple extension which allows for another way to
> > specify a date range, as np.arange(datetime, timedelta, timedelta).
>
> instead of, or in addition to, the above?
>
In addition to.
> it seems you can pass in the following types:
>
> strings
> np.datetime64
> np.timedelta64
> integers
> (floats ?)
>
It's like pretty much everywhere in NumPy, where conversion to the target
type is done when needed.
Are you essentially doing method overloading to determine what it all means?
>
That's right, if any of the start, stop, or step are datetime-related types
(including python datetime types), or the dtype provided is
datetime/timedelta, it calls the datetime-specific arange function.
How do you know if:
>
> np.arange('2011', '2020', dtype='M8[Y]')
>
Only timedeltas and integers result in the (datetime, timedelta) mode.
Specifying an integer directly as a datetime is itself a very odd thing, as
a timedelta it makes much more sense.
means you want from the years 2011 to 2020 or from 2011 to 4031?
>
>>> np.arange('2011', '2020', dtype='M8[Y]')
array(['2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018',
'2019'], dtype='datetime64[Y]')
> >>> np.arange('today', 10, 3, dtype='M8')
> > array(['2011-06-09', '2011-06-12', '2011-06-15', '2011-06-18'],
> > dtype='datetime64[D]')
>
> so dtype 'M8' defaults to increments of days?
>
No, 'M8' means generic/unspecified units, and 'today' defaults to units of
days. The generic units are similar to how the string dtype doesn't specify
a size.
of course, I've lost track of the difference between 'M' and 'M8'
>
> (I've never liked the dtype code anyway -- I far prefer np.float64 to
> 'd', for instance)
>
> Will there be a "linspace" for datetimes?
>
That can certainly be done, yes.
-Mark
-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
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110609/2a0c995a/attachment.html>
More information about the NumPy-Discussion
mailing list