Skip to content

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

Description

@anishmehta24

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

  • Component: Python SDK

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions