[Numpy-discussion] type-casting inconsistency with timedelta64
Charles R Harris
charlesr.harris@gmail....
Fri Sep 16 15:50:59 CDT 2011
On Fri, Sep 16, 2011 at 2:28 PM, Benjamin Root <ben.root@ou.edu> wrote:
> Came across an oddity when experimenting with the datetime64 and
> timedelta64 objects.
>
> a = np.zeros((10,), dtype='l')
> b = np.datetime64('2010-12-20T14:23:56-0600')
> c = np.datetime64('2010-12-20T21:27:09-0600')
>
> a[0:1] = c - b # This works fine
> a[0] = c - b # This does not
>
>
> The second assignment throws the following error:
> TypeError: don't know how to convert scalar number to long
>
>
Certainly inconsistent:
In [8]: (c - b).astype(long)
Out[8]: 25393
In [9]: a[0] = (c - b).astype(long)
works. I don't think either should work without an explicit cast because the
units get lost.
>
> P.S. - np.arange() can make ranges of datetime64 from string inputs, but
> np.linspace() can not (and does not take a dtype kwarg).
>
>
A dtype keyword would be problematic since linspace needs to have fractions
to do the division. On the other hand, having a convenient way to produce
equally spaced time sounds useful. Hmm...
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110916/844c6a0f/attachment.html
More information about the NumPy-Discussion
mailing list