[Python] Round float seconds to the nearest microsecond in Duration - #40236
Open
anishmehta24 wants to merge 1 commit into
Open
anishmehta24 wants to merge 1 commit into
anishmehta24 wants to merge 1 commit into
Conversation
anishmehta24
force-pushed
the
fix/timestamp-float-seconds-rounding
branch
from
September 23, 2026 10:16
9da5881 to
5eb2e27
Compare
Contributor
|
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
Author
|
assign set of reviewers |
Contributor
|
Assigning reviewers: R: @claudevdm for label python. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
anishmehta24
force-pushed
the
fix/timestamp-float-seconds-rounding
branch
from
September 24, 2026 16:11
5eb2e27 to
e4966b0
Compare
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Duration(seconds)truncates instead of rounding whensecondsis a float, so it can land one microsecond below the value passed in:seconds * 1000000is a float multiplication that often lands just under the exact integer (2.000002 * 1e6 == 2000001.9999999998) andint()truncates it. #40257 fixed this for theTimestampconstructor;Duration.__init__had the same line, so this usesround()there too, same as theTimestampfix (microskeepsint(), matching it).Test:
DurationTest.test_constructor_float_rounds_to_nearestcovers positive, negative,Duration.of, an exact value, and microsecond values round-tripped through float seconds. It fails on master.apache_beam/utils/timestamp_test.py43 passed, yapf clean.Fixes #40263