使用CnosDB的Python连接器与pandas一起使用,但返回的响应没有数据。

huangapple go评论93阅读模式
英文:

Using CnosDB python connector with pandas, but the returned response has no data

问题

今天早上我把数据集放入 cnosdb,想要用 pandas 找一些系数,但看起来连接器无法解析响应,所以打印出这样的响应:

   area  dv  time
0  area  dv  time
1  area  dv  time
2  area  dv  time

> 这是我的环境。
>
> - 操作系统:Windows 11 家庭版,而不是 WSL
> - Python 3.11.4
> - pandas 2.0.2
> - cnos-connector 0.1.8
> - CnosDB: tag-v2.3.1 4b169315

以下是重现错误的最小命令:

1. 准备

## 写入三行数据
> curl -X POST -u 'root:' ‘http://127.0.0.1:8902/api/v1/write?db=public’ -d 'ds,area=a1 dv=1'
> curl -X POST -u 'root:' ‘http://127.0.0.1:8902/api/v1/write?db=public’ -d 'ds,area=a1 dv=2'
> curl -X POST -u 'root:' ‘http://127.0.0.1:8902/api/v1/write?db=public’ -d 'ds,area=a1 dv=3'
## 安装 cnos-connector
> pip install cnos-connector
Collecting cnos-connector
  Downloading cnos_connector-0.1.8-py3-none-any.whl (7.6 kB)
Installing collected packages: cnos-connector
Successfully installed cnos-connector-0.1.8
## 运行 Python CLI
> python
>>> from cnosdb_connector import connect
>>> import pandas as pd
>>> conn = connect(url="http://127.0.0.1:8902/", user="root", password="")

2. 进行查询

## 执行查询
>>> resp = pd.read_sql("SELECT * FROM ds", conn)
<stdin>:1: UserWarning: pandas only supports SQLAlchemy connectable (engine/connection) or database string URI or sqlite3 DBAPI2 connection. Other DBAPI2 objects are not tested. Please consider using SQLAlchemy.
## 打印响应
>>> print(resp)
   area  dv  time
0  area  dv  time
1  area  dv  time
2  area  dv  time

响应中只有列名,没有任何数据。

  • 我使用了错误版本的连接器吗?
  • 我使用了错误版本的文档吗?

已解决

这是因为我使用的是 pandas v2,而该连接器仅适用于 pandas v1。

英文:

I put the dataset into cnosdb this morning and wanna use pandas to find some coefficients, but it looks like the connector can't parse the response so that it prints the response like this:

   area  dv  time
0  area  dv  time
1  area  dv  time
2  area  dv  time

> Here is my env.
>
> - OS: windows-11 home edition, not the WSL
> - Python 3.11.4
> - pandas 2.0.2
> - cnos-connector 0.1.8
> - CnosDB: tag-v2.3.1 4b169315

Here is the minimal commands to re-produce the error, following this page: reference/connector/python.html .

1. Prepare

## write three rows of data
> curl -X POST -u 'root:' ‘http://127.0.0.1:8902/api/v1/write?db=public’ -d 'ds,area=a1 dv=1'
> curl -X POST -u 'root:' ‘http://127.0.0.1:8902/api/v1/write?db=public’ -d 'ds,area=a1 dv=2'
> curl -X POST -u 'root:' ‘http://127.0.0.1:8902/api/v1/write?db=public’ -d 'ds,area=a1 dv=3'
## install the cnos-connector
> pip install cnos-connector
Collecting cnos-connector
  Downloading cnos_connector-0.1.8-py3-none-any.whl (7.6 kB)
Installing collected packages: cnos-connector
Successfully installed cnos-connector-0.1.8
## run python cli
> python
>>> from cnosdb_connector import connect
>>> import pandas as pd
>>> conn = connect(url="http://127.0.0.1:8902/", user="root", password="")

2. Do the query

## Execute the query
>>> resp = pd.read_sql("SELECT * FROM ds", conn)
<stdin>:1: UserWarning: pandas only supports SQLAlchemy connectable (engine/connection) or database string URI or sqlite3 DBAPI2 connection. Other DBAPI2 objects are not tested. Please consider using SQLAlchemy.
## Print the response
>>> print(resp)
   area  dv  time
0  area  dv  time
1  area  dv  time
2  area  dv  time

Responses are all the column-names without any data.

  • Am I using the wrong version of the connector?
  • Am I using the wrong version of the document?

Solved

It's because I am using pandas v2, this connector only works on pandas v1.

答案1

得分: 2

我无法重现这个错误。如果这个错误在你那里继续出现,请给我回复更多细节,比如通过CnosDB-CLI直接查询的结果和cnosdb的日志等。

英文:

I cannot reproduce this bug. If this bug continues to appear in your place, please reply me with more details, such as the results of direct query through CnosDB-CLI and the logs of cnosdb, etc.

答案2

得分: 1

这个问题似乎在 cnos-connector 0.1.9 中已经解决了。

英文:

This issue seems to have been solved in cnos-connector 0.1.9

huangapple
  • 本文由 发表于 2023年6月26日 00:27:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76551405.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定