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

query_data_frame returns object data type for all columns #379

Closed
buraketmen opened this issue Dec 8, 2021 · 1 comment · Fixed by #380
Closed

query_data_frame returns object data type for all columns #379

buraketmen opened this issue Dec 8, 2021 · 1 comment · Fixed by #380
Labels
bug Something isn't working
Milestone

Comments

@buraketmen
Copy link

buraketmen commented Dec 8, 2021

Steps to reproduce:

  1. Transferring data types (numeric, object etc.) to dataframe

Expected behavior:

Returning the data types of the data pulled from the database with query_api as it should be.

Actual behavior:

When I use the following query with the query_data_frame module in the query_api, all columns except _time are returned as objects; even though the data stored in the database is not string.

query_api = influxdb_client.query_api()
bucket, measurement, start, stop ="test", "test", "0", "now()"

query = 'import \"influxdata/influxdb/schema\"' \
  f' from(bucket:\"{bucket}\")' \
  f' |> range(start: {start}, stop: {stop})' \
  f' |> filter(fn: (r) => r._measurement == \"{measurement}\")' \
  f' |> drop(columns: ["_start", "_stop","_measurement"])' \
  f' |> schema.fieldsAsCols()'

result = query_api.query_data_frame(query=query)
print(result.dtypes)

_time           datetime64[ns, UTC]
attribute_1                  object
attribute_2                  object
attribute_3                  object

When I transform the data with the code below, I can see that the data is numeric, not object. The data which is saved in the database is as follows:

result = json.loads(result.to_json(orient='records'))
print(result)

[{
  "_time": 1638959688782,
  "attribute_1": 1,
  "attribute_2": 2,
  "attribute_3": "test_message",
}]

Specifications:

  • Client Version: 1.23.0
  • InfluxDB Version: 2.2.1
  • Platform: Windows 10 & Python3.8.11 (running on Docker)
@bednar
Copy link
Contributor

bednar commented Dec 9, 2021

Hi @buraketmen,

thanks for using our client.

I have prepared a fixed version within #380. If you would like to use this fixed version before regular release, please install client via:

pip install git+https://github.com/influxdata/influxdb-client-python.git@fix/pandas-data-types

Regards

@bednar bednar added the bug Something isn't working label Dec 9, 2021
@bednar bednar added this to the 1.25.0 milestone Dec 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants