KxSystems / pyq

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

Bug: Global variable treated as splayed table column #115

Closed antipisa closed 4 years ago

antipisa commented 5 years ago

Assigning in q under the global context usually works fine

$ pyq
Python 3.7.2 (default, Dec 29 2018, 06:25:15)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> q.a = 10
>>> q.a
k('10')

But when the first variable in the global context is a splayed table, and we’re no longer in that mount point, pyq throws an error:

$ pyq
Python 3.7.2 (default, Dec 29 2018, 06:25:15)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> q('`:/var/tmp/test/table/ set ([]til 10)') #create splayed table
k('`:/var/tmp/test/table/')
>>> q('\l /var/tmp/test') #mount the directory to bring table into context
k('::')
>>> q('key `.')
k(',`table')
>>> q('\cd /var/tmp') #change directory to somewhere else so table is no longer valid
k('::')
>>> q.a = 10
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/zodiac/.conda/envs/dev2/lib/python3.7/site-packages/pyq/__init__.py", line 723, in __setattr__
    self("@[`.;;:;]", attr, value)
  File "/home/zodiac/.conda/envs/dev2/lib/python3.7/site-packages/pyq/__init__.py", line 706, in __call__
    return K._k(0, m, *map(K, args))
  File "/home/zodiac/.conda/envs/dev2/lib/python3.7/site-packages/pyq/__init__.py", line 1058, in _trp_k
    return cls_._trp(f, K(args))
_k.error: ('table/x. OS reports: No such file or directory', k('(((k){(x[y;](. z)@)\'!z};15);(();"<q>";-1;"k){(x[y;](. z)@)\'!z}");14;3);(();((..'))
('table/x. OS reports: No such file or directory', k('(((k){(x[y;](. z)@)\'!z};15);(();"<q>";-1;"k){(x[y;](. z)@)\'!z}");14;3);(();((..'))

If we assign a variable in the global context before the splayed table, everything works as expected:

$ pyq
Python 3.7.2 (default, Dec 29 2018, 06:25:15)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> q.z = 10
>>> q('`:/var/tmp/test/table/ set ([]til 10)')
k('`:/var/tmp/test/table/')
>>> q('\l /var/tmp/test')
k('::')
>>> q('key `.')
k('`z`table')
>>> q('\cd /var/tmp')
k('::')
>>> q.a = 10
>>> q.a
k('10')
github-actions[bot] commented 4 years ago

Stale issue message