Skip to content

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

Merged
merged 2 commits into from
Apr 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions rerun_py/rerun_sdk/rerun/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,11 @@ def to_nanos(duration: int | np.integer | float | np.float64 | timedelta | np.ti
def to_nanos_since_epoch(
timestamp: int | np.integer | float | np.float64 | datetime | np.datetime64,
) -> int:
if isinstance(timestamp, (int, np.integer)):
return 1_000_000_000 * int(timestamp) # Interpret as seconds and convert to nanos
elif isinstance(
timestamp,
# Only allowing f64 since anything less has way too little precision for measuring time since 1970
(float, np.float64),
):
# Interpret as seconds and convert to nanos
return int(np.round(1e9 * timestamp))
# Only allowing f64 since anything less has way too little precision for measuring time since 1970
if isinstance(timestamp, (int, np.integer, float, np.float64)):
if timestamp > 1e11:
raise ValueError("set_time: Expected seconds since unix epoch, but it looks like this is in milliseconds")
return int(np.round(1e9 * timestamp)) # Interpret as seconds and convert to nanos
elif isinstance(timestamp, datetime):
if timestamp.tzinfo is None:
timestamp = timestamp.replace(tzinfo=timezone.utc)
Expand Down
Loading