[Numpy-discussion] datetime64

Pierre GM pgmdevlist@gmail....
Thu Nov 19 17:25:12 CST 2009


On Nov 19, 2009, at 5:40 PM, Fernando Perez wrote:
> 
> we're starting to use these tools more and more, and with the 1.4
> release coming out, we're a bit lost here...

Welcome to the club... 
Fernando, Ariel, I'm in the same spot as you are, I haven't been able to use it. I don't think it's that a good idea to advertise it in the upcoming release notes...

In addition to your observations, here's something that surprised me:
>>>  x=np.array([datetime.date(2001,_,1) for _ in range(1,13)], dtype="M8[M]")
array([2001-01-01 00:00:00, 2001-02-01 00:00:00, 2001-03-01 00:00:00,
       2001-04-01 00:00:00, 2001-05-01 00:00:00, 2001-06-01 00:00:00,
       2001-07-01 00:00:00, 2001-08-01 00:00:00, 2001-09-01 00:00:00,
       2001-10-01 00:00:00, 2001-11-01 00:00:00, 2001-12-01 00:00:00], dtype=datetime64[M])
>>> x.dtype
dtype('datetime64[M]')
>>> x.astype("M8[Y]")
array([2342-01-01 00:00:00, 2343-01-01 00:00:00, 2344-01-01 00:00:00,
       2345-01-01 00:00:00, 2346-01-01 00:00:00, 2347-01-01 00:00:00,
       2348-01-01 00:00:00, 2349-01-01 00:00:00, 2350-01-01 00:00:00,
       2351-01-01 00:00:00, 2352-01-01 00:00:00, 2353-01-01 00:00:00], dtype=datetime64[Y])
>>> x.astype("M8[Y]")
array([2342-01-01 00:00:00, 2343-01-01 00:00:00, 2344-01-01 00:00:00,
       2345-01-01 00:00:00, 2346-01-01 00:00:00, 2347-01-01 00:00:00,
       2348-01-01 00:00:00, 2349-01-01 00:00:00, 2350-01-01 00:00:00,
       2351-01-01 00:00:00, 2352-01-01 00:00:00, 2353-01-01 00:00:00], dtype=datetime64[Y])
>>> x.dtype
dtype('datetime64[Y]')

Besides the fact that having to use a comprehension list is a bit of an hassle, I'm surprised that astype modifies my array in place...

Mind you, I'm very grateful for Travis O's work on np.datetime64 and I'm quite excited to have time support in numpy directly... eventually. I'm sure we can get something ready for 1.5. Just let me know how I can help.







More information about the NumPy-Discussion mailing list