Skip to content

Preserve exact fractional Unix timestamps in from_format - #1047

Open
FanWu-ai wants to merge 2 commits into
python-pendulum:masterfrom
FanWu-ai:fix-exact-fractional-unix-timestamps-20261012
Open

FanWu-ai wants to merge 2 commits into
python-pendulum:masterfrom
FanWu-ai:fix-exact-fractional-unix-timestamps-20261012

Conversation

@FanWu-ai

@FanWu-ai FanWu-ai commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Pull Request Check List

  • Added tests for changed code.
  • Updated documentation for changed code.

Fix

from_format('0.000001', 'X') loses the microsecond; from_format('0.000012', 'X') raises ValueError; and from_format('-0.1', 'X') returns .100000 rather than .900000 in the preceding second. Negative x millisecond values are likewise incorrect. Float conversion also loses precision at large timestamps and can round the final valid microsecond beyond year 9999.

Parse the existing X/x grammars into exact integer microseconds and obtain calendar fields with stdlib epoch-plus-timedelta arithmetic. Timezone attachment remains unchanged. Add 26 regressions/controls and timestamp documentation examples.

Validation and CI correction

The first submitted head passed full local pure-Python and release-native checks, but hosted native testing failed on the retained year-1 case. CI uses Rust's debug profile; the existing native local_time helper panics with unsigned overflow there, while release arithmetic wraps. This exposed a gap in the initial local build-profile coverage.

The corrective commit avoids that helper using exact stdlib integer date arithmetic. Every test and documentation byte is retained, including year 1/year 9999. No Rust code, overflow settings, dependencies, skips or check configuration were changed.

Revised validation on Linux:

  • Fresh upstream debug-native baselines on Python 3.10.22/3.12.14: 1,871 passed / 3 existing skips. The first submitted code independently reproduces the single debug-native failure on both versions.
  • Final complete debug-native and pure suites on both Python versions: 1,897 passed / 3 existing skips each.
  • Rebuilt release Python 3.12 wheel, native and pure complete suites: 1,897 passed / 3 existing skips each.
  • Strict mypy (228 files), all six pinned hooks including Rust formatting/Clippy, strict MkDocs, debug/release packages, strict Twine and artifact-source comparisons pass.
  • 40,412 exact-integer public-API checks and independent 4,127-case oracles pass. Explicit provenance probes verify debug overflow checks remain active while the corrected public formatter handles year 1.

The unchanged skips cover Windows-only behavior and upstream timezone-transition limits. Existing INFO-level docs anchor notices and Cargo packaging diagnostics remain. Replacement hosted CI and other platforms are not claimed passed until verified. Prepared and tested with AI assistance (OpenAI Codex); no human review is claimed.

Parse X and x tokens into integer microseconds before splitting normalized seconds and fractions. Avoid negative-fraction errors, scientific-notation failures and float precision loss.

AI assistance: OpenAI Codex.
@FanWu-ai
FanWu-ai marked this pull request as ready for review October 11, 2026 22:26
@codspeed

codspeed Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ 1 benchmark spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

ℹ️ 1 benchmark has no flame graph

The flamegraph could not be generated because we failed to resolve the symbols in the profiling trace. This happens when we fail to harvest information about language frames.

✅ 1 untouched benchmark


Comparing FanWu-ai:fix-exact-fractional-unix-timestamps-20261012 (d0b04f3) with master (7840d47)

Open in CodSpeed

@FanWu-ai
FanWu-ai marked this pull request as draft October 11, 2026 22:32
Use exact stdlib epoch arithmetic instead of the existing Rust local_time helper. Preserve every regression and documentation assertion, including year1 and year9999, and verify full debug-native and pure suites on Python3.10 and3.12.

AI assistance: OpenAI Codex.
@FanWu-ai
FanWu-ai marked this pull request as ready for review October 11, 2026 22:41

This branch has not been deployed

No deployments
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.

1 participant