You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Timestamp(float seconds) truncates instead of rounding, losing a microsecond #40235
seconds * 1e6 is a float multiplication, so for many values it lands just under the exact integer (2.000002 * 1e6 == 2000001.9999999998), and int() truncates toward zero rather than rounding to nearest:
This hits the most common way of building a timestamp, Timestamp.of(time.time()):
>>>t=time.time() # 1790158166.5462177>>>Timestamp.of(t).micros1790158166546217# the float is ...546218 to the microsecond
Taking microsecond values, converting them to float seconds the way a caller would, and feeding them back in, 1.2% come back one microsecond low (2436 of 200000 random epoch-range values).
The class docstring says "If seconds is a float, the fractional part will be captured up to precision digits", and explains that integer storage is used precisely because "floating point values lose precision" — but the conversion into that integer storage is itself lossy. Truncation is also asymmetric about zero, which sits oddly with "an int of floored seconds".
I'd like to work on this — the fix is to round (rather than truncate) the float-to-micros conversion in the Timestamp constructor, plus a regression test. .take-issue
Activity
[Python] Round float seconds to the nearest unit in Timestamp
[Python] Round float seconds to the nearest unit in Timestamp and Dur…
DeepikaMamidipelly009 commentedon Sep 24, 2026
I'd like to work on this — the fix is to round (rather than truncate) the float-to-micros conversion in the Timestamp constructor, plus a regression test. .take-issue
Round float seconds to nearest subsecond unit in Timestamp constructor (