exxeleron / qPython

interprocess communication between Python and kdb+
http://www.devnet.de
Apache License 2.0
151 stars 90 forks source link

Pandas Series: Numeric indices that do not contain zero #28

Closed 691175002 closed 9 years ago

691175002 commented 9 years ago

Attempting to write a DataFrame/Series with an integer index that does not contain zero will throw an exception:

df = DataFrame({'k':[1,2,3],'v':['a','b','c']}).set_index('k')
q.sync('`test set',df)

File "C:\Anaconda3\envs\pyq\lib\site-packages\qpython\_pandas.py", line 157, in _write_pandas_series
    qtype = Q_TYPE.get(type(data[0]), QGENERAL_LIST)
KeyError: 0

This is caused by the data[0] lookup. With a non-numeric index data[0] will return the first row as expected, however when the index is numeric it will search for 0 and find nothing. Explicit indexing by row number (via iloc) fixes the issue.

_pandas.py:157
    qtype = Q_TYPE.get(type(data[0]), QGENERAL_LIST)
    qtype = Q_TYPE.get(type(data.iloc[0]), QGENERAL_LIST)
maciejlach commented 9 years ago

Thank you for the report and proposed solution. Please checkout latest qPython version.