-
-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -635,7 +635,7 @@ def __rtruediv__(self, other): | |
|
||
@unpack_zerodim_and_defer("__floordiv__") | ||
def __floordiv__(self, other): | ||
|
||
# breakpoint() | ||
if is_scalar(other): | ||
if isinstance(other, self._recognized_scalars): | ||
other = Timedelta(other) | ||
|
@@ -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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. -> #44471 |
||
freq = None | ||
if self.freq is not None: | ||
# Note: freq gets division, not floor-division | ||
|
@@ -661,7 +660,7 @@ def __floordiv__(self, other): | |
# e.g. if self.freq is Nano(1) then dividing by 2 | ||
# rounds down to zero | ||
freq = None | ||
return type(self)(result.view("m8[ns]"), freq=freq) | ||
return type(self)(result, freq=freq) | ||
|
||
if not hasattr(other, "dtype"): | ||
# list, tuple | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 |
||
tdser = Series(["59 Days", "59 Days", "NaT"], dtype="m8[ns]") | ||
expected = Series(["29.5D", "29.5D", "NaT"], dtype="timedelta64[ns]") | ||
|
||
tdser = tm.box_expected(tdser, box_with_array) | ||
expected = tm.box_expected(expected, box_with_array) | ||
|
||
result = tdser // two | ||
tm.assert_equal(result, expected) | ||
|
||
with pytest.raises(TypeError, match="Cannot divide"): | ||
two // tdser | ||
|
||
@pytest.mark.parametrize( | ||
"vector", | ||
[np.array([20, 30, 40]), pd.Index([20, 30, 40]), Series([20, 30, 40])], | ||
|
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