-
Notifications
You must be signed in to change notification settings - Fork 15
fix: 103 batch write example #112
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #112 +/- ##
==========================================
+ Coverage 55.12% 59.52% +4.39%
==========================================
Files 33 33
Lines 2048 2048
==========================================
+ Hits 1129 1219 +90
+ Misses 919 829 -90 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Unrelated (I think), but tests/test_write_file.py
is failing:
> pytest
========================================================================================================================================= test session starts ==========================================================================================================================================
platform darwin -- Python 3.11.9, pytest-7.4.1, pluggy-1.3.0
rootdir: /Users/ja/Documents/github/influxdb3-python
configfile: pytest.ini
plugins: cov-2.12.1, pytest_codeblocks-0.16.1, anyio-4.3.0, dotenv-0.5.2
collected 62 items
tests/test_api_client.py ....... [ 11%]
tests/test_dataframe_serializer.py ........................ [ 50%]
tests/test_date_helper.py ... [ 54%]
tests/test_deep_merge.py ....... [ 66%]
tests/test_influxdb_client_3.py ... [ 70%]
tests/test_influxdb_client_3_integration.py ssssss [ 80%]
tests/test_merge_options.py .... [ 87%]
tests/test_point.py .. [ 90%]
tests/test_polars.py .. [ 93%]
tests/test_query.py ... [ 98%]
tests/test_write_file.py F [100%]
=============================================================================================================================================== FAILURES ===============================================================================================================================================
__________________________________________________________________________________________________________________________________ TestWriteFile.test_write_file_csv ___________________________________________________________________________________________________________________________________
self = <tests.test_write_file.TestWriteFile testMethod=test_write_file_csv>
def test_write_file_csv(self):
mock_write = Mock(spec=WriteApi)
self.client._write_api.write = mock_write.write
self.client.write_file(file='tests/data/iot.csv', timestamp_column='time', measurement_name="iot-devices",
tag_columns=["building"], write_precision='s')
expected_df = pd.DataFrame({
"name": ['iot-devices', 'iot-devices', 'iot-devices'],
"building": ['5a', '5a', '5a'],
"temperature": [72.3, 72.1, 72.2],
"time": pd.to_datetime(["2022-10-01T12:01:00Z", "2022-10-02T12:01:00Z", "2022-10-03T12:01:00Z"])
.astype('datetime64[s, UTC]'),
})
expected = {
'bucket': 'my_db',
'record': expected_df,
'data_frame_measurement_name': 'iot-devices',
'data_frame_tag_columns': ['building'],
'data_frame_timestamp_column': 'time',
'write_precision': 's'
}
_, actual = mock_write.write.call_args
assert mock_write.write.call_count == 1
> assert expected_df.equals(actual['record'])
E assert False
E + where False = <bound method NDFrame.equals of name building temperature time\n0 iot-devices 5a...devices 5a 72.1 2022-10-02 12:01:00+00:00\n2 iot-devices 5a 72.2 2022-10-03 12:01:00+00:00>( name building temperature time\n0 iot-devices 5a 72.3 2022-10-01 12:01:0...-devices 5a 72.1 2022-10-02 12:01:00+00:00\n2 iot-devices 5a 72.2 2022-10-03 12:01:00+00:00)
E + where <bound method NDFrame.equals of name building temperature time\n0 iot-devices 5a...devices 5a 72.1 2022-10-02 12:01:00+00:00\n2 iot-devices 5a 72.2 2022-10-03 12:01:00+00:00> = name building temperature time\n0 iot-devices 5a 72.3 2022-10-01 12:01:0...-devices 5a 72.1 2022-10-02 12:01:00+00:00\n2 iot-devices 5a 72.2 2022-10-03 12:01:00+00:00.equals
tests/test_write_file.py:52: AssertionError
======================================================================================================================================= short test summary info ========================================================================================================================================
FAILED tests/test_write_file.py::TestWriteFile::test_write_file_csv - assert False
================================================================================
batch_size = 10 | ||
|
||
def success(conf, data): | ||
nonlocal write_success, write_count |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
I didn't know about nonlocal
print(f"Elapsed time ms: {int(callback.elapsed() / 1_000_000)}") | ||
|
||
|
||
if __name__ == "__main__": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
Closes #103
Proposed Changes
batching_example.py
to show making calls after the context manager for the write has closed.Checklist