-
-
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
Conversation
Travis timeout |
Codecov Report
@@ Coverage Diff @@
## master #18831 +/- ##
==========================================
- Coverage 91.58% 91.58% -0.01%
==========================================
Files 150 150
Lines 48972 48972
==========================================
- Hits 44851 44849 -2
- Misses 4121 4123 +2
Continue to review full report at Codecov.
|
Series([0, 0, np.nan])) | ||
# TODO: the Timedelta // td1 fails because of a bug | ||
# in Timedelta.__floordiv__, see GH#18824 | ||
# tm.assert_series_equal(tdscalar // td1, Series([1, 1, np.nan])) |
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.
I would consider breaking out into a separate test so we can xfail
it separately.
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.
Works for me. I've got a fix ready pending feedback on #18846.
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.
yes would clean up these tests here (IIRC you broke these out by operator elsewhere)
doc/source/whatsnew/v0.22.0.txt
Outdated
@@ -354,3 +354,4 @@ Other | |||
|
|||
- Improved error message when attempting to use a Python keyword as an identifier in a ``numexpr`` backed query (:issue:`18221`) | |||
- Bug in :class:`Timestamp` where comparison with an array of ``Timestamp`` objects would result in a ``RecursionError`` (:issue:`15183`) | |||
- Bug in :func:`Series.__floordiv__` and :func:`Series.__rfloordiv__` where operating on a scalar ``timedelta`` raises an exception (:issue:`18824`) |
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.
don't put things in Other. This is conversion. Also note that a floordiv of scalar / Series was incorrect before.
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.
verify that we have a doc example in timedelta.rst 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.
Also note that a floordiv of scalar / Series was incorrect before.
Something other than the mention of Series.__rfloordiv__
?
Series([0, 0, np.nan])) | ||
# TODO: the Timedelta // td1 fails because of a bug | ||
# in Timedelta.__floordiv__, see GH#18824 | ||
# tm.assert_series_equal(tdscalar // td1, Series([1, 1, np.nan])) |
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.
yes would clean up these tests here (IIRC you broke these out by operator elsewhere)
tdscalar - td1 | ||
td1 / tdscalar | ||
tdscalar / td1 | ||
tm.assert_series_equal(td1 // tdscalar, Series([0, 0, np.nan])) |
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 parametrize these last ones they seem pretty similar
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.
This is part of a 127 line test that is all over the place. I'd prefer to clean it up in a follow-up.
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.
ok, this needs parameterization / refactor, but can follow up.
@@ -962,6 +962,14 @@ def test_timedelta64_ops_nat(self): | |||
|
|||
|
|||
class TestDatetimeSeriesArithmetic(object): | |||
@pytest.mark.xfail(reason='GH#18824 bug in Timedelta.__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.
is this the right issue?
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.
AFAIK there is no dedicated issue. I made a checkbox for this in 18224.
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.
don't mark 18224, its way to big to figure out what you are talking about (you can certainly reference this PR which is I think what you are doing). rather list the PR number (if there isn't an issue). do this generally.
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.
lgtm. some doc changes. ping on green.
@@ -962,6 +962,14 @@ def test_timedelta64_ops_nat(self): | |||
|
|||
|
|||
class TestDatetimeSeriesArithmetic(object): | |||
@pytest.mark.xfail(reason='GH#18824 bug in Timedelta.__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.
don't mark 18224, its way to big to figure out what you are talking about (you can certainly reference this PR which is I think what you are doing). rather list the PR number (if there isn't an issue). do this generally.
doc/source/whatsnew/v0.23.0.txt
Outdated
@@ -282,6 +282,7 @@ Conversion | |||
- Bug in :meth:`Index.astype` with a categorical dtype where the resultant index is not converted to a :class:`CategoricalIndex` for all types of index (:issue:`18630`) | |||
- Bug in :meth:`Series.astype` and ``Categorical.astype()`` where an existing categorical data does not get updated (:issue:`10696`, :issue:`18593`) | |||
- Bug in :class:`Series` constructor with an int or float list where specifying ``dtype=str``, ``dtype='str'`` or ``dtype='U'`` failed to convert the data elements to strings (:issue:`16605`) | |||
- Bug in :func:`Series.__floordiv__` and :func:`Series.__rfloordiv__` where operating on a scalar ``timedelta`` raises an exception (:issue:`18824`) |
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.
I would just say floor division here.
tdscalar - td1 | ||
td1 / tdscalar | ||
tdscalar / td1 | ||
tm.assert_series_equal(td1 // tdscalar, Series([0, 0, np.nan])) |
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.
ok, this needs parameterization / refactor, but can follow up.
Ping |
Looks like a test got lost in the last merge, will need to track that down. If there's a way to cancel the CI run, go for it. |
@pytest.mark.parametrize('scalar_td', [ | ||
timedelta(minutes=5, seconds=4), | ||
pytest.param(Timedelta('5m4s'), | ||
marks=pytest.mark.xfail(reason="Timedelta.__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.
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__
and Timedelta.__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 because Timedelta.__floordiv__
gets called, not Timedelta.__rfloordiv__
.
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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
then make another test for it
thanks! |
closes #18846
Before:
After
Also identified a bug in
Timedelta.__floordiv__
, noted it in #18824, will address that separately.git diff upstream/master -u -- "*.py" | flake8 --diff