chore: refactor examples#209
Conversation
… underscores. More review notes.
…py as downsample.py
…_.py (decouple from project).
036586f to
9a7e664
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #209 +/- ##
=======================================
Coverage 75.17% 75.17%
=======================================
Files 35 35
Lines 2417 2417
=======================================
Hits 1817 1817
Misses 600 600 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Refactors and standardizes the repository’s Python examples by consolidating them under a new lowercase examples/ layout, removing older/duplicated example sets, and adding updated “core / write / query / advanced / jupyter” examples intended to be either functional or explicitly illustrative.
Changes:
- Move/replace legacy
Examples/content with a new structuredexamples/tree (core/write/query/advanced/jupyter) and update CI linting to target it. - Add/refresh functional and illustrative example scripts (timeouts, batching, pandas, file import, query modes, async query, middleware, SSL).
- Add supporting example assets (source data files + updater helper) and an
examples/README.mdplus a small prep helper script.
Reviewed changes
Copilot reviewed 45 out of 53 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| examples/write/writeoptions.py | New write options example; adds illustrative callbacks and sync write usage. |
| examples/write/fileimport.py | New file-import example that writes from local source_data files and uses batching callbacks. |
| examples/write/batching.py | Updated batching write example; switches to env vars and reduces output verbosity. |
| examples/write/pandas_write.py | New pandas DataFrame write example with dynamic timestamps. |
| examples/write/handle_http_error.py | Updates write error-handling example to use env vars and adds shebang/header. |
| examples/write/source_data/* | Adds local CSV/JSON/Feather/ORC/Parquet source data plus updater script and pokemon dataset. |
| examples/query/query_modes.py | New example demonstrating query modes (chunk/pandas/all/schema/reader). |
| examples/query/query_async.py | Updates async query example; adds env vars, shebang, and naming fixes. |
| examples/query/query_with_middleware.py | Updates middleware example to use env vars and adds descriptive header. |
| examples/query/handle_query_error.py | Updates query error-handling example to use env vars and direct imports. |
| examples/query/flight_options.py | New illustrative example for Arrow Flight / gRPC options. |
| examples/core/basic_write.py | New basic “Point write” example using env vars. |
| examples/core/basic_query.py | New basic query example meant to follow basic_write. |
| examples/core/basic_ssl.py | Updates SSL example to use env vars and expanded guidance. |
| examples/core/timeouts.py | Updates timeouts example to use env vars and improved header docs. |
| examples/advanced/downsample.py | New functional downsampling example using local pokemon CSV. |
| examples/advanced/database_transfer.py | Updates illustrative transfer example to use env vars and reorganized imports. |
| examples/jupyter/basic-write-query.ipynb | Adds a basic write/query Jupyter notebook walkthrough. |
| examples/prep.py | Adds helper to install extra deps and chmod shebang-based example scripts. |
| examples/README.md | New top-level documentation describing example structure and configuration. |
| .circleci/config.yml | Updates flake8 path from Examples/ to examples/. |
Comments suppressed due to low confidence (1)
examples/write/batching.py:60
- The comments/logging imply
target_sample_countis the number of points written, but the nestedfor gatewayId in gatewayIdsloop means the script writestarget_sample_count * len(gatewayIds)points. Consider renaming variables and updating any progress/summary messages so they reflect the actual number of points written (and fix the nearby comment that mentions 5,000 gatewayIds vs the 100 created).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 45 out of 53 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 45 out of 53 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (2)
examples/query/query_async.py:83
InfluxDBClient3is created without a context manager or an explicitclose(). Since the client manages network resources/threads, this example may leak resources or hang at shutdown in some environments. Preferwith InfluxDBClient3(...) as client:(even inside the asyncmain) or ensureclient.close()is called in afinallyblock.
examples/write/batching.py:37- The write batching callbacks annotate
dataasstr, but the client delivers the batch payload as raw line-protocolbytes(the write API encodes strings before enqueueing). Update the type annotations tobytes(and keep any formatting consistent with bytes) to prevent confusion and accidental double-encoding in copied code.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 45 out of 53 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Refactors examples.
Renames
Examplesdir toexamples.Further changes described in the following notes.
Refactoring Notes
pokemon-trainerand refactor examples tocore,writeandquerybasic-write-errorhandling.pycan be removed. DONEhandle_http_error.pyandhandle_query_error.pybasic-write-writeoptions.pyto./writerefactored DONEpandas-write.pycan be removed - duplicates./pandas_write.pyDONEwrite-batching.pycan be removed - duplicates./batching_example.pyDONEwrite-batching-flight-call-options.pyto be removed DONEcookbook.ipynb- most of this is migrated to./jupyter/basic-write-query.ipynb- can be removed DONEfile-importas single file, with source data updatable - seeupdater.pyDONE./communityexamples.custom_url.pyDONEDoesn't query Influxdb directly but down samples from remote CSV./advancedDONEgithubusercontentDONEdatabase_transfer.pydbfromand measurementairSensorsto exist../advancedDONEmake functionalkept as illustrative -advanced/downsample.pyis similar and functionalbasic_ssl_examle.pyto./coreDONEbatching_example.pyto./writeDONEcloud_dedicated_query.py- is it necessary to have specific cloud_dedicated examples? Can this simply be documented inREADME.mdor in code comments? (Removed DONE)cloud_dedicated_write.py- is it necessary to have specific cloud_dedicated examples? Can this simply be documented inREADME.mdor in code comments? (Removed DONE)config.py- universal configuration file. Keep as is.example.csv- where is this used? It doesn't seem to be used in any example... ??? (Removed DONE)flight_options_example.py- to./queryDONENote only option illustrated is tls certificate.handle_http_error.py- to./writeDONEhandle_query_error.py- to./queryDONEpandas_write.py- to./writeDONEquery_async.py- to./queryDONEquery_type.py- rename toquery_modes.py. Move to./queryDONEquery_with_middleware.py- to./queryDONEtimeouts.py- to./coreDONEdata_frame_measurement_nameordata_frame_tag_columnsDONE../githubusercontent/../*.csvDONELeverageDONEconfig.pyin all exampleswriteoptions.py- does not show much in the way of setting options. (Update and revision - DONE)basic_ssl.py- review. Seems to only show handling SSL handshake failures. (Reviewed and updated - DONE)write_pandas.py- has fixed dates from 2023, make dynamic with current. DONEflight_options.py- review. This example is nearly three years old, and flight/query options has been greatly enhanced since then. DONE*. NOTE - If making an illustrative example functional out-of-the-box leads to too much distractive information being added, leave the example as illustrative only and add a comment that it is for purposes of illustration. However, make sure the illustrative example is still working in a concrete implementation. (e.g.
query_with_middleware.py)*. In comments, mark examples as either illustrative or functional DONE
Standardization summary (F - functional, I - illustrative)
Config()file_write())Checklist