influxdata / influxdata/influxdb-client-python
Column Open of a Pandas DataFrame is lost
Open
Nobody has claimed this yet.
bug
- Dominant language
- Python
- Stars
- 793
- Forks
- 186
- Avg merge
- 3h 2m
- Merged PRs (30d)
- 1
Description
Specifications
- Client Version: latest from pip
- InfluxDB Version: v2.7.1
- Platform: Windows 10
Code sample to reproduce problem
download.py
import datetime
from binance_historical_data import BinanceDataDumper
data_dumper = BinanceDataDumper(
path_dir_where_to_dump=".",
asset_class="spot", # spot, um, cm
data_type="klines", # aggTrades, klines, trades
data_frequency="1h",
)
data_dumper.dump_data(
tickers="BTCUSDT",
date_start=datetime.date(2023, 7, 1),
date_end=None,
is_to_update_existing=False,
)
store.py
from influxdb_client import InfluxDBClient, WriteOptions
import datetime
import pandas as pd
data_source = "binance"
asset_class = "spot" # spot, um, cm
storage_frequency = "daily" # daily, monthly
data_type = "klines" # aggTrades, klines, trades
symbol = "BTCUSDT"
data_frequency = "1h"
dt = datetime.date(2023, 7, 1)
fname = f"C:\\Users\\w4c\\data\\{data_source}\\{asset_class}\\{storage_frequency}\\{data_type}\\{symbol}\\{data_frequency}\\{symbol}-{data_frequency}-{dt.year}-{dt.month:02}-{dt.day:02}.csv"
with InfluxDBClient.from_env_properties() as client:
columns = [
"OpenTime",
"Open",
"High",
"Low",
"Close",
"Volume",
"CloseTime",
"Quote asset volume",
"Number of trades",
"Taker buy base asset volume",
"Taker buy quote asset volume",
"Ignore",
]
for df in pd.read_csv(fname, chunksize=1_000, names=columns):
# for col in ["OpenTime", "CloseTime"]:
for col in ["OpenTime"]:
df[col] = pd.to_datetime(df[col], unit="ms")
df["CloseTime"] *= 1_000_000
df["data_source"] = data_source
df["asset_class"] = asset_class
df["data_type"] = data_type
df["data_frequency"] = data_frequency
df["symbol"] = symbol
print(df)
print(df.dtypes)
with client.write_api() as write_api:
try:
write_api.write(
record=df,
bucket="data",
data_frame_measurement_name="crypto",
data_frame_tag_columns=["data_source", "asset_class", "data_type", "symbol", "data_frequency"],
data_frame_timestamp_column="OpenTime",
)
except Exception as e:
print(e)
Open column is not displayed
Additional info
No response
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run download.py to produce the CSV, then use store.py to reproduce the write with the printed DataFrame and dtypes. Trace how the pandas DataFrame is converted for the InfluxDB write and compare the stored fields with the input columns. Done means the Open column is retained and displayed with the other written data.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- pandas, python
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100