beam icon indicating copy to clipboard operation
beam copied to clipboard

[Bug]: Duration(float seconds) truncates instead of rounding, losing a microsecond

Open anishmehta24 opened this issue 2 months ago • 1 comments

What happened?

Duration(seconds) truncates instead of rounding when seconds is a float, so it can land one microsecond below the value passed in. This is the same thing #40235 described for Timestamp, which #40257 fixed, but Duration.__init__ still does:

self.micros = int(seconds * 1000000) + int(micros)
>>> from apache_beam.utils.timestamp import Duration
>>> Duration(2.000002).micros
2000001          # expected 2000002
>>> Duration(-2.000002).micros
-2000001         # expected -2000002

Using round() like the Timestamp constructor now does fixes it.

Issue Priority

Priority: 3 (minor)

Issue Components

  • [x] Component: Python SDK

anishmehta24 avatar Sep 24 '26 16:09 anishmehta24

.take-issue

anishmehta24 avatar Sep 24 '26 16:09 anishmehta24