Skip to content

fix: avoid timestamp rounding across precision boundaries - #724

Draft
Kayvan-Zahiri wants to merge 1 commit into
influxdata:masterfrom
Kayvan-Zahiri:codex/avoid-float-timestamp-rounding
Draft

Kayvan-Zahiri wants to merge 1 commit into
influxdata:masterfrom
Kayvan-Zahiri:codex/avoid-float-timestamp-rounding

Conversation

@Kayvan-Zahiri

@Kayvan-Zahiri Kayvan-Zahiri commented Oct 23, 2026 •

Copy link
Copy Markdown

Proposed Changes

Avoid floating-point division when reducing datetime/timedelta nanoseconds to microseconds, milliseconds, or seconds in Point line protocol. Near an interval boundary, float rounding can move the timestamp into the next interval before the final integer conversion.

For example, with the documented PandasDateTimeHelper, a timestamp of 1700000000000000999 ns is serialized at microsecond precision as 1700000000000001, although truncation gives 1700000000000000.

Use exact integer arithmetic, preserving the existing truncation-toward-zero behavior for negative timestamps. Nanosecond precision and integer timestamp inputs retain their existing paths.

Validation

  • Public Point.time(...).to_line_protocol() tests cover positive and negative pandas timestamps just before and exactly on microsecond/millisecond/second boundaries, plus unchanged nanosecond precision.
  • Before: 6 regressions fail; 8 controls pass.
  • After: 65 pass across the new tests, test_point.py, test_DateHelper.py, and test_PandasDateTimeHelper.py.
  • Changed-file Flake8, compileall, and git diff --check pass.
  • Full flake8 setup.py influxdb_client/ reports two existing E721 diagnostics in _async/api_client.py:270 and _sync/api_client.py:287. Unchanged point.py produces byte-for-byte identical output. No diagnostics are suppressed.
  • No live InfluxDB instance or credentials used; full server integration suite and Python-version matrix not run locally.

Checklist

  • CHANGELOG.md updated
  • Regression tests added
  • Targeted point/date tests pass
  • Full pytest tests integration suite (requires InfluxDB)
  • Conventional commit message
  • InfluxData CLA submitted with explicit contributor authorization; the official form confirmed "Your response has been recorded." Maintainer-side verification may still be pending.

AI assistance: OpenAI Codex assisted with reproduction, patch, tests, and this description.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.47%. Comparing base (ef60f89) to head (c403555).

Files with missing lines Patch % Lines
influxdb_client/client/write/point.py 80.00% 1 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #724      +/-   ##
==========================================
- Coverage   90.49%   90.47%   -0.03%     
==========================================
  Files          40       40              
  Lines        3568     3570       +2     
==========================================
+ Hits         3229     3230       +1     
- Misses        339      340       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants