KxSystems / pyq

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

Minor issue in ,: append with pyq #70

Closed pindash closed 6 years ago

pindash commented 6 years ago

Questions

Steps to reproduce the issue

from pyq import q
def test(x,y):
    return {"x":x, "y":y}

q.set('f',test)
q('g:{d:`x`y!(x+x;y);d,:f (x;y)}')
q('g[4;5]')

Expected result

`x`y!4 5

Actual result

type error

Workaround

two workarounds are known change function g to g:{d:xy!(x+x;y);d:d,f (x;y)} explicitly cast g:{d:xy!(x+x;y); d,:`long$f(x,y)}

abalkin commented 6 years ago

I cannot reproduce your error. With a 32-bit version on macOS, I get

>>> from pyq import q
>>> def test(x,y):
...     return {"x":x, "y":y}
...
>>> q.set('f',test)
k('`f')
>>> q('g:{d:`x`y!(x+x;y);d,:f (x;y)}')
k('::')
>>> q('g[4;5]')
k('::')

I am not sure why you expect any return from g, as written it properly returns ::, but if I add an explicit return, I get your expected result:

>>> q('g:{d:`x`y!(x+x;y);:d,:f (x;y)}')
k('::')
>>> q('g[4;5]')
k('`x`y!4 5')
abalkin commented 6 years ago

Note that since you are using Python 2.7, the order of keys in a dictionary is not guaranteed, so your f is equally likely to return

`x`y!4 5

or

`y`x!5 4

This ambiguity, however does not seem to be able to cause a type error.

Please try to add a debug print to your function

q('g:{d:`x`y!(x+x;y);d,:0N!f (x;y)}')

and report the result.

abalkin commented 6 years ago

BTW, what version of kdb+ are you using? Under kdb+ 2.x 4 5 without a suffix produces ints, not longs.

abalkin commented 6 years ago

Closing as "invalid" after no response from OP.