KxSystems / pyq

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

Comparing K scalars in pyq requires types to match #86

Closed antipisa closed 6 years ago

antipisa commented 6 years ago

Comparing scalars in K requires the exact type to be match, which is not consistent with the comparison in plain q or numpy.

This comparison in kdb q)7h = 7 returns True.

From the pyq-kernel, however

q('7h') == 7
False

and even

q('7h') == q('7')
False

Ideally this should return True to be consistent with numpy:

np.int16(7) == np.int64(7)
True
abalkin commented 6 years ago

This is intentional. == in pyq corresponds to ~ in q.

q)7h~7
0b

If you want behavior similar to that of numpy, you can use the = function from q

>>> eq(7, 7.0)
k('1b')

note, however that = in q uses a tolerance.

>>> eq(1-1/3, 2/3)
k('1b')
>>> 1-1/3 == 2/3
False