exxeleron / qPython

interprocess communication between Python and kdb+
http://www.devnet.de
Apache License 2.0
152 stars 89 forks source link

Timezone issues #29

Closed szs8 closed 8 years ago

szs8 commented 8 years ago

It seems that np.datetime64 assumes UTC when KDB is showing a local timestamp. Any way to get around this?

In [67]: conn.sync("string .z.Z")
Out[67]: '2015.08.25T18:03:28.368'

In [69]: print conn.sync(".z.Z")
2015-08-25T14:03:36.137-0400 [metadata(qtype=-15)]
maciejlach commented 8 years ago

The IPC protocol doesn't provide timezone information while transferring datetime objects. E.g. datetime is represented as a float value under the hood:

q).z.Z
2015.08.27T11:22:34.759
q)9h$.z.Z
5717.474

While creating np.datetime64 objects, qPython is not aware of timezone connected with datetime. Moreover, timezone handling in numpy is not perfect.

You could call .item() on a np.datetime64 object to get a naive datetime object that represents time in UTC:

>>> dt = q('.z.Z')
>>> print dt.raw
2015-08-27T13:26:44.963+0200
>>> print dt.raw.item()
2015-08-27 11:26:44.963000