beam
beam copied to clipboard
[Bug]: Duration(float seconds) truncates instead of rounding, losing a microsecond
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
.take-issue