-
Notifications
You must be signed in to change notification settings - Fork 185
When ingest dataframe, use alternative tagging #94
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
Comments
@cjelsa thanks for the issue. we will take a look. |
Hi @cjelsa, Did you try the default tags? It will also work for ingesting DataFrame. https://github.com/influxdata/influxdb-client-python#default-tags Regards |
No, I have not and I didn't know it worked for DataFrame ingestion as well. I think I can get it working from there. So I use the PointSettings() function? |
Yes, you could use something like: settings = PointSettings(**{"NASDAQ": "AAPL", "type": "technology"})
write_client = self.client.write_api(point_settings=settings) |
Hmm. It seems that PointSettings is not really working. This is my code, where contract is a tuple: point_settings = PointSettings() Error: NameError Traceback (most recent call last) NameError: name 'PointSettings' is not defined |
And this is also not right ;-) File "", line 30 |
Hi @cjelsa, it looks like you are missed a correct import of I prepared an example: How to ingest DataFrame with default tags. You could use it as a start point to your implementation. Regards |
Hi, That is exactly right, I didn't import that ;-). Now the problem moves to the following: TypeError Traceback (most recent call last) TypeError: 'Stock' object is not subscriptable Any idea? |
It is caused by Try to extract tag values and then set it into ticker = contract[0]
exchange = contract[1]
currency = contract[2]
point_settings = PointSettings()
point_settings.add_default_tag('ticker', ticker)
point_settings.add_default_tag('exchange', exchange)
point_settings.add_default_tag('currency', currency) |
Ok, yes. That was not the smartest thing ;-) But still it looks like the point_settings method is not really working. Data gets injected without point_settings default tags, but with data_frame_measurement_name. The Code: client = InfluxDBClient(url=inflx_url, token=inflx_token, org=inflx_org) p_settings = PointSettings() write_api.write(bucket=inflx_bucket, record=df, data_frame_measurement_name='IB_Hist_Data', point_settings=p_settings) But no tags get written. When I check: Input: Output: So the logic seems to work, only the writing to DB doesn't seem to work. |
It's strange. Try to display raw data in Data Explorer or enable client = InfluxDBClient(url=inflx_url, token=inflx_token, org=inflx_org, debug=True) |
Raw data doesn't change much, just the view, see picture. I tried again with debug set to true (I masked the token): send: b'POST /api/v2/write?org=PA&bucket=data&precision=ns HTTP/1.1\r\nHost: localhost:9999\r\nAccept-Encoding: identity\r\nContent-Length: 137850\r\nContent-Encoding: identity\r\nContent-Type: text/plain\r\nAccept: application/json\r\nAuthorization: Token XXXXXXXXXXXc-XXXXXXXXXXXXXXXXXXXXX7Zg==\r\nUser-Agent: influxdb-client-python/1.8.0dev\r\n\r\n' No sign of the tags... |
The client = InfluxDBClient(url=inflx_url, token=inflx_token, org=inflx_org)
p_settings = PointSettings()
p_settings.add_default_tag('ticker', c)
p_settings.add_default_tag('exchange', scope_primary_exchange)
p_settings.add_default_tag('currency', scope_currency)
p_settings.add_default_tag('data_type', 'bar_data_1s')
write_api = client.write_api(write_options=SYNCHRONOUS, point_settings=p_settings)
write_api.write(bucket=inflx_bucket, record=df, data_frame_measurement_name='IB_Hist_Data') |
Yes! Thank you very much! |
Thank you. |
In addition to ticket #79
Would it be possible to next to, data_frame_tag_columns=tag_columns, also have a 'data_frame_tag=' argument? This way a tag can be added to a DF which doesn't appear in the DF.
For example, I have a DF with stock prices: timestamp, open, high, low, close (etc) data. I would like to be able to add tags as ticker, exchange etc which don't appear in the DF, by using a 'data_frame_tag=' argument with data_frame_tag='NASDAQ', 'AAPL'
The text was updated successfully, but these errors were encountered: