-
Notifications
You must be signed in to change notification settings - Fork 451
Improve set_time
error handling for large Python integers
#9839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,11 +101,18 @@ def set_time( | |
) | ||
elif timestamp is not None: | ||
nanos = to_nanos_since_epoch(timestamp) | ||
bindings.set_time_timestamp_nanos_since_epoch( | ||
timeline, | ||
nanos, | ||
recording=recording.to_native() if recording is not None else None, | ||
) | ||
try: | ||
bindings.set_time_timestamp_nanos_since_epoch( | ||
timeline, | ||
nanos, | ||
recording=recording.to_native() if recording is not None else None, | ||
) | ||
except OverflowError as err: | ||
raise ValueError( | ||
f"set_time: `timestamp={timestamp!r}` is out of range; " | ||
f"expected seconds since Unix epoch, datetime.datetime, or numpy.datetime64 " | ||
f"(timeline='{timeline}')" | ||
) from err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How large integers were you passing in, and why? And shouldn't we protect against the same problem for sequence and duration timelines too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was passing a timestamp in milliseconds since unix epoch, e.g. '1_745_943_196_000'. But since we assume seconds, it would then be multiplied by 1e9 to convert to nanoseconds. I don't think sequence and duration suffer from the same gotcha, so I'd argue it's not necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds like we could improve the error message then with something along the lines of: if 1_500_000_000_000 < timestamp < 2_000_000_000_000:
raise "Expected seconds since unix epoch, but it looks like this is milliseconds" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea I like this more as well. However Let's check if timestamp is bigger than |
||
|
||
|
||
def to_nanos(duration: int | np.integer | float | np.float64 | timedelta | np.timedelta64) -> int: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the
!r
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It formats the value using
repr()
, instead ofstr()
.would result in:
Figured that this would be desired to clearly show which type is being used, since we can take in numpy integers, python integers and floats iirc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL!