On Thu, Mar 20, 2014 at 6:32 PM, Alexander Belopolsky
The difference comes down to I/O.
It is more than I/O. It is also about interoperability with Python's datetime module.
Sorry -- I was using I/O to mean "converting to/from datetime64 and other types" So that included datetime.datetime. Here is the behavior that I don't like in the current implementation:
d = array(['2001-01-01T12:00'], dtype='M8[ms]') d.item(0) datetime.datetime(2001, 1, 1, 17, 0)
yup , it converted to UTC using your locale setting -- really not good! Then tossed that our when creating a datetime.datetime. This really is quite broken. But this brings up a good point -- having time zone handling fully compatible ith datetime.datetime would have its advantages. So use the same tzinfo API. If I understand NEP correctly, the proposal is to make d.item(0) return
d.item(0).replace(tzinfo=timezone.utc) datetime.datetime(2001, 1, 1, 12, 0, tzinfo=datetime.timezone.utc)
instead. But this is not what I would expect: I want
d.item(0) datetime.datetime(2001, 1, 1, 12, 0)
When I work with naive datetime objects I don't want to be exposed to timezones at all.
right -- naive time zones really would be good. The problem now with the current code and your example, is that in:
d = array(['2001-01-01T12:00'], dtype='M8[ms]')
'2001-01-01T12:00' is interpreted as meaning "in the machines locale time zone" combining that with teh UTC assumption, and you have trouble. The work around for what you want now is to add TZ info to the string: In [56]: d = np.array(['2001-01-01T12:00Z'], dtype='M8[ms]') In [57]: d.item(0) Out[57]: datetime.datetime(2001, 1, 1, 12, 0) or: In [60]: d = np.array(['2001-01-01T12:00-00:00'], dtype='M8[ms]') In [61]: d.item(0) Out[61]: datetime.datetime(2001, 1, 1, 12, 0) I _think_ that's what you want. This is what I mean that naive and UTC are almost the same. -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@noaa.gov