Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: AttributeError: 'list' object has no attribute 'tolist' when insert_dataframe with use_numpy on #218

Closed
panwenbin opened this issue May 14, 2021 · 5 comments

Comments

@panwenbin
Copy link

Describe the bug
get a dataframe by query_dataframe() then insert it by insert_dataframe(), an error occurs.

To Reproduce

test.a has a column of Array(String)

df = client.query_dataframe("SELECT * FROM test.a LIMIT 10;")
client.insert_dataframe("INSERT INTO test.b VALUES ", df, settings={"use_numpy": True})

got:
Traceback (most recent call last):
File "ch_test.py", line 7, in
client.insert_dataframe("INSERT INTO test.b VALUES ", df, settings={"use_numpy": True})
File "/home/panwenbin/github/panwenbin/ch_test/venv/lib/python3.7/site-packages/clickhouse_driver/client.py", line 418, in insert_dataframe
query_id=query_id, settings=settings
File "/home/panwenbin/github/panwenbin/ch_test/venv/lib/python3.7/site-packages/clickhouse_driver/client.py", line 245, in execute
columnar=columnar
File "/home/panwenbin/github/panwenbin/ch_test/venv/lib/python3.7/site-packages/clickhouse_driver/client.py", line 472, in process_insert_query
types_check=types_check, columnar=columnar)
File "/home/panwenbin/github/panwenbin/ch_test/venv/lib/python3.7/site-packages/clickhouse_driver/client.py", line 524, in send_data
self.connection.send_data(block)
File "/home/panwenbin/github/panwenbin/ch_test/venv/lib/python3.7/site-packages/clickhouse_driver/connection.py", line 554, in send_data
self.block_out.write(block)
File "/home/panwenbin/github/panwenbin/ch_test/venv/lib/python3.7/site-packages/clickhouse_driver/streams/native.py", line 39, in write
self.fout, types_check=block.types_check)
File "/home/panwenbin/github/panwenbin/ch_test/venv/lib/python3.7/site-packages/clickhouse_driver/columns/service.py", line 107, in write_column
column.write_data(items, buf)
File "/home/panwenbin/github/panwenbin/ch_test/venv/lib/python3.7/site-packages/clickhouse_driver/columns/arraycolumn.py", line 44, in write_data
self._write(data, buf)
File "/home/panwenbin/github/panwenbin/ch_test/venv/lib/python3.7/site-packages/clickhouse_driver/columns/arraycolumn.py", line 104, in _write
self._write_data(value, buf)
File "/home/panwenbin/github/panwenbin/ch_test/venv/lib/python3.7/site-packages/clickhouse_driver/columns/arraycolumn.py", line 88, in _write_data
self.nested_column._write_data(value, buf)
File "/home/panwenbin/github/panwenbin/ch_test/venv/lib/python3.7/site-packages/clickhouse_driver/columns/arraycolumn.py", line 88, in _write_data
self.nested_column._write_data(value, buf)
File "/home/panwenbin/github/panwenbin/ch_test/venv/lib/python3.7/site-packages/clickhouse_driver/columns/base.py", line 81, in _write_data
self.write_items(prepared, buf)
File "/home/panwenbin/github/panwenbin/ch_test/venv/lib/python3.7/site-packages/clickhouse_driver/columns/numpy/stringcolumn.py", line 22, in write_items
return buf.write_strings(items.tolist(), encoding=self.encoding)
AttributeError: 'list' object has no attribute 'tolist'

Expected behavior
expected without error

Versions

  • clickhouse-driver: 0.2.0
  • python: 3.7.3
@etadelta222
Copy link

etadelta222 commented Aug 4, 2021

I've run into issue using insert_dataframe as well. I've followed the above suggestions from issue but am getting errors. When I use settings={"use_numpy":True}>

I end up getting the error below when trying to call client.insert_datafram('INSERT INTO [table] VALUES',df)

AttributeError: 'numpy.ndarray' object has no attribute 'values'

I've tried using settings={"use_pandas":True} and end up with the error below:

TypeError: Unsupported column type: <class 'numpy.ndarray'>. list or tuple is expected.

When I tried to convert the df to a list and pass it in it gives the error below:

AttributeError: 'list' object has no attribute 'transpose'

When I set transpose=False it gives the error below:

AttributeError: 'list' object has no attribute 'values'

Any idea what I'm doing wrong here?

python = 3.8.2
clickhouse-driver = 0.2.1

@etadelta222
Copy link

@panwenbin , please see this ticket: #76
I've included my resolution, hopefully that helps you, if you haven't solved this already.

@ghego
Copy link

ghego commented Jan 28, 2022

problem still persisting. Anyone has a solution?

clickhouse-driver = 0.2.2

@xzkostyan
Copy link
Member

@ghego master branch has fix for this bug you can install package directly form github.

@duy-effectiv
Copy link

Update to the latest ver 0.2.3 and the problem is sorted out
pip3 install --upgrade clickhouse-driver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants