Skip to content
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

bug: interval addition/subtraction should upcast to smallest unit #6139

Closed
1 task done
jcrist opened this issue May 3, 2023 · 0 comments · Fixed by #6203
Closed
1 task done

bug: interval addition/subtraction should upcast to smallest unit #6139

jcrist opened this issue May 3, 2023 · 0 comments · Fixed by #6203
Labels
bug Incorrect behavior inside of ibis

Comments

@jcrist
Copy link
Member

jcrist commented May 3, 2023

What happened?

Currently adding/subtracting intervals results in an interval with a unit of the left operand. This can result in accidental information loss if the smaller unit in the operation is the right operand:

In [1]: import ibis

In [2]: one_second = ibis.interval(seconds=1)

In [3]: two_minutes = ibis.interval(minutes=2)

In [4]: (one_second + two_minutes).type().unit
Out[4]: <IntervalUnit.SECOND: 's'>

In [5]: (two_minutes + one_second).type().unit  # I'd expect seconds here too
Out[5]: <IntervalUnit.MINUTE: 'm'>

In [6]: (one_second + two_minutes).execute()
Out[6]: Timedelta('0 days 00:02:01')

In [7]: (two_minutes + one_second).execute()  # the second is dropped on rounding to minutes
Out[7]: Timedelta('0 days 00:02:00')

The offending code is here. With some pointers I can probably fix this. I know we have casting utilities for handling integer upcasting, but I'm not sure if the same exists for intervals.

What version of ibis are you using?

dev

What backend(s) are you using, if any?

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect behavior inside of ibis
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant