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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]