我正试图通过qpython查询特定函数。函数需要一个包含多个参数的字典,第一个参数是日期(类型-14),第二个参数是分钟列表(类型17)
我写了一个小例子,希望能忠实地说明这个问题:
\d .test
testfun:{[args]
one:args[`one];
two:args[`two];
' string type args[`two];
:42;
};
现在,当我通过qpython查询时:
from qpython import qconnection
from qpython.qcollection import QDictionary, qlist
import numpy as np
from qpython.qtype import QLONG_LIST, QSYMBOL_LIST, QMINUTE_LIST
query='{[arg_dict] :.test.testfun[arg_dict] }'
kdbconfig = {
'q_host': 'q_host',
'q_port': 42,
'q_usr': 'q_usr',
'q_pwd': 'q_pwd'
}
params = {
"one" : np.datetime64('2021-01-06', 'D'),
"two" : qlist([ np.timedelta64(10*60, 'm'), np.timedelta64(10*60+30, 'm')] , qtype = QMINUTE_LIST)
}
qparams = QDictionary(list(params.keys()), list(params.values()))
with qconnection.QConnection(host=kdbconfig['q_host'],
port=kdbconfig['q_port'],
username=kdbconfig['q_usr'],
password=kdbconfig['q_pwd'] ) as q:
data = q.sendSync(query, qparams, pandas = True)
if data is None:
raise ValueError("didnt return any data")
但是我得到了QException: b'-14'
,而我希望输入17qparams.values
值:[numpy.datetime64('2021-01-06'), QList([420, 450], dtype='timedelta64[m]')]
所以在我看来这是合理的
任何人都会有一个想法如何使这项工作,请
密钥将作为字符串而不是符号发送:
`two根据字典中第一项的类型返回null。我不确定qpython如何处理字符串和符号,但您可以将q函数更新为:
编辑:如何调试
如果查询正在发送到q进程ok,那么最好在kdb端进行调试,如果查询没有按预期进行。我将测试q函数定义为:
这允许我查看kdb接收到的内容。在
np.string_
上有一个很好的例子,它将其定义为符号:您还可以如下定义q函数,使其返回python:
我的剧本:
相关问题 更多 >
编程相关推荐