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
naturaltime() and precisedelta() raise OverflowError on float('inf'), unlike naturaldelta() #524
The same result from all three. Since #334 (which closed #333), naturaldelta returns a non-finite value as its string, and its docstring says so.
What actually happened?
naturaldelta inf -> 'inf'
naturaldelta nan -> 'nan'
naturaltime inf -> OverflowError cannot convert float infinity to integer
naturaltime nan -> 'nan'
precisedelta inf -> OverflowError cannot convert float infinity to integer
precisedelta nan -> 'nan'
naturaltime and precisedelta already return 'nan', so only infinity is the odd one out. It comes from _date_and_delta, where timedelta(seconds=value) raises OverflowError; naturaldelta catches that for non-finite values and the other two do not.
I have a small change that mirrors #334 in the other two functions (a finite value that is too large, such as 1e30, still raises). I have not opened it, because #448 and #456 are reworking the same path and #434 adds a test that expects naturaltime(inf) to raise. Should inf be handled like in naturaldelta, and if so would you rather it went into those PRs or a separate one?
Activity