-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: fix timedelta floordiv with scalar float #44466
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: fix timedelta floordiv with scalar float #44466
Conversation
@@ -1987,6 +1987,20 @@ def test_td64arr_div_numeric_scalar(self, box_with_array, two): | |||
with pytest.raises(TypeError, match="Cannot divide"): | |||
two / tdser | |||
|
|||
@pytest.mark.parametrize("two", [2, 2.0, np.array(2), np.array(2.0)]) | |||
def test_td64arr_floordiv_numeric_scalar(self, box_with_array, two): |
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.
We have versions above of this test for multiplication and division, so adding one for floordiv as well
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.
can you add a whatsnew note, comment and lgtm
pandas/core/arrays/timedeltas.py
Outdated
@@ -635,7 +635,7 @@ def __rtruediv__(self, other): | |||
|
|||
@unpack_zerodim_and_defer("__floordiv__") | |||
def __floordiv__(self, other): | |||
|
|||
# breakpoint() |
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.
can you remove
Hmm, so apparently it already passes on all numpy versions we test. OK, will clean-up then :) |
@@ -651,8 +651,7 @@ def __floordiv__(self, other): | |||
|
|||
# at this point we should only have numeric scalars; anything | |||
# else will raise | |||
result = self.asi8 // other | |||
np.putmask(result, self._isnan, iNaT) | |||
result = self._ndarray / other |
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.
why is this using div instead of floordiv?
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.
Because I was stupid .. :), and because the test I added (or any other test we already have) actually don't catch this because only use such data that it is the same for div or floordiv ..
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.
-> #44471
Discovered while trying to fix test failures in #40482. Currently normal division with a float scalar works, but floordiv doesn't (returns garbage):
It's only the scalar case; dividing with eg float array already works:
I suppose the current code uses the workaround of
asi8
and casting back to timedelta, because numpy didn't support floordiv in the past (didn't check which version started to implement this, will see what CI says)