-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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 Series[timedelta64] arithmetic with Timedelta scalars #18831
Changes from 14 commits
1eab96f
25071a8
45c7260
95cc5f9
6ff2d5f
4fe8f74
4821f05
10054de
66561ef
347a221
8789be7
c3795d0
ef8d6e2
2b3484f
3250913
3a5c3b5
729d240
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 |
---|---|---|
|
@@ -977,9 +977,7 @@ def test_operators_timedelta64_with_timedelta(self, scalar_td): | |
|
||
@pytest.mark.parametrize('scalar_td', [ | ||
timedelta(minutes=5, seconds=4), | ||
pytest.param(Timedelta('5m4s'), | ||
marks=pytest.mark.xfail(reason="Timedelta.__floordiv__ " | ||
"bug GH#18846")), | ||
Timedelta('5m4s'), | ||
Timedelta('5m4s').to_timedelta64()]) | ||
def test_operators_timedelta64_with_timedelta_invalid(self, scalar_td): | ||
td1 = Series([timedelta(minutes=5, seconds=3)] * 3) | ||
|
@@ -993,15 +991,44 @@ def test_operators_timedelta64_with_timedelta_invalid(self, scalar_td): | |
td1 * scalar_td | ||
with tm.assert_raises_regex(TypeError, pattern): | ||
scalar_td * td1 | ||
with tm.assert_raises_regex(TypeError, pattern): | ||
td1 // scalar_td | ||
with tm.assert_raises_regex(TypeError, pattern): | ||
scalar_td // td1 | ||
with tm.assert_raises_regex(TypeError, pattern): | ||
scalar_td ** td1 | ||
with tm.assert_raises_regex(TypeError, pattern): | ||
td1 ** scalar_td | ||
|
||
@pytest.mark.parametrize('scalar_td', [ | ||
timedelta(minutes=5, seconds=4), | ||
pytest.param(Timedelta('5m4s'), | ||
marks=pytest.mark.xfail(reason="Timedelta.__floordiv__ " | ||
"bug GH#18846")), | ||
Timedelta('5m4s').to_timedelta64()]) | ||
def test_timedelta_rfloordiv(self, scalar_td): | ||
# GH#18831 | ||
td1 = Series([timedelta(minutes=5, seconds=3)] * 3) | ||
td1.iloc[2] = np.nan | ||
result = scalar_td // td1 | ||
expected = Series([1, 1, np.nan]) | ||
tm.assert_series_equal(result, expected) | ||
|
||
@pytest.mark.parametrize('scalar_td', [ | ||
timedelta(minutes=5, seconds=4), | ||
Timedelta('5m4s'), | ||
Timedelta('5m4s').to_timedelta64()]) | ||
def test_timedelta_floordiv(self, scalar_td): | ||
# GH#18831 | ||
td1 = Series([timedelta(minutes=5, seconds=3)] * 3) | ||
td1.iloc[2] = np.nan | ||
|
||
result = td1 // scalar_td | ||
expected = Series([0, 0, np.nan]) | ||
tm.assert_series_equal(result, expected) | ||
|
||
# We can test __rfloordiv__ using this syntax, | ||
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. shouldn't this be in the other test? (as the other one is rfloordiv), but this seems to work? 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. It's kind of a man without a country regardless. I didn't want to put it in the rfloordiv test because that was xfailed so putting it there would be akin to not running it at all. But you're right it doesn't really belong in the floordiv test either. I'm open to suggestions. 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. then make another test for it |
||
# see `test_timedelta_rfloordiv` | ||
result = td1.__rfloordiv__(scalar_td) | ||
expected = Series([1, 1, np.nan]) | ||
tm.assert_series_equal(result, expected) | ||
|
||
|
||
class TestDatetimeSeriesArithmetic(object): | ||
@pytest.mark.parametrize( | ||
|
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.
floordiv -> rfloordiv
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.
? Both
Timedelta.__floordiv__
andTimedelta.__rfloordiv__
are wonky. Or are you referring to something else?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.
you reason is wrong, it should be rfloordiv
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.
You mean the
reason="Timedelta.__floordiv__
...? The test fails becauseTimedelta.__floordiv__
gets called, notTimedelta.__rfloordiv__
.