KxSystems / pyq

PyQ — Python for kdb+
http://code.kx.com/q/interfaces
Apache License 2.0
190 stars 49 forks source link

Converting scalar timestamp/timedeltas to numpy arrays #85

Closed antipisa closed 4 years ago

antipisa commented 6 years ago

What is the right way to convert a scalar timestamp/timedelta from kdb to numpy?

I notice that this works:

np.asarray(q('1#.z.P'))[0]
numpy.datetime64('2018-08-05T15:14:49.636201000’)

but this does not:

np.datetime64(q('.z.P'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Could not convert object to NumPy datetime

Same thing for timespans:

np.asarray(q('1#`timespan$0'))[0]
numpy.timedelta64(0,'ns')

np.timedelta(q('`timespan$0'))
abalkin commented 6 years ago

You can do

>>> numpy.asarray(q('.z.P').enlist)[0]
numpy.datetime64('2018-08-05T19:26:35.701942000')

but we will look into a way to make

np.datetime64(q('.z.P'))

work.

abalkin commented 6 years ago

SyntaxError: invalid syntax

In your last example, you are missing a quote mark.

github-actions[bot] commented 4 years ago

Stale issue message