-
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
Conversation
rerun_py/rerun_sdk/rerun/time.py
Outdated
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 comment
The 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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Yea I like this more as well. However 2_000_000_000_000
is only valid for about 8 years.
Let's check if timestamp is bigger than 1e11
which will always mean milliseconds instead of seconds 👍
rerun_py/rerun_sdk/rerun/time.py
Outdated
) | ||
except OverflowError as err: | ||
raise ValueError( | ||
f"set_time: `timestamp={timestamp!r}` is out of range; " |
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 of str()
.
import numpy as np
a = np.int64(123)
b = 123
print(f"{a!r} {a}")
print(f"{b!r} {b}")
would result in:
np.int64(123) 123
123 123
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!
Related
set_time
Cannot handle large Python integers #9822What
Adds a clear error message when
set_time
receives an out-of-range timestamp.