You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "Deepika-lab (via GitHub)" <gi...@apache.org> on 2026/09/24 04:10:33 UTC
[PR] Round float seconds to nearest subsecond unit in Timestamp constructor [beam]
Deepika-lab opened a new pull request, #40257:
URL: https://github.com/apache/beam/pull/40257
Fixes #40235
The `Timestamp` constructor converted float seconds to the internal integer representation with `int()`, which truncates toward zero. Because most decimal fractions are not exactly representable in binary (e.g. `2.000002 * 1e6 == 2000001.9999999998`), this landed one subsecond unit below the caller's value in about 1.2% of cases — including the common `Timestamp.of(time.time())` path — and was asymmetric about zero.
This change uses `round()` instead of `int()` for the `seconds * 10**precision` conversion, matching the documented behavior ("the fractional part will be captured up to precision digits") and restoring symmetry about zero for negative timestamps. Integer inputs and exact float values are unaffected, and `divmod` still floors so subseconds stay non-negative.
Also updates the class docstring to say the fractional part is rounded to the nearest subsecond unit, and adds a regression test (`test_constructor_float_rounds_to_nearest`).
Tests run:
- `python -m pytest apache_beam/utils/timestamp_test.py` — 42 passed (41 existing + 1 new)
- Checked that no other SDK tests assert the old truncation behavior.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Round float seconds to nearest subsecond unit in Timestamp constructor [beam]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #40257:
URL: https://github.com/apache/beam/pull/40257#issuecomment-5808149297
Assigning reviewers:
R: @jrmccluskey for label python.
Note: If you would like to opt out of this review, comment `assign to next reviewer`.
Available commands:
- `stop reviewer notifications` - opt out of the automated review tooling
- `remind me after tests pass` - tag the comment author after tests pass
- `waiting on author` - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)
The PR bot will only process comments in the main thread (not review comments).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Round float seconds to nearest subsecond unit in Timestamp constructor [beam]
Posted by "jrmccluskey (via GitHub)" <gi...@apache.org>.
jrmccluskey merged PR #40257:
URL: https://github.com/apache/beam/pull/40257
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org