-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Tests for TDI issues already fixed #19044
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
Conversation
fix a couple others caused by failing to return NotImplemented or to override names correctly
doc/source/whatsnew/v0.23.0.txt
Outdated
@@ -300,7 +300,9 @@ Conversion | |||
- Bug in :class:`FY5253` where ``datetime`` addition and subtraction incremented incorrectly for dates on the year-end but not normalized to midnight (:issue:`18854`) | |||
- Bug in :class:`DatetimeIndex` where adding or subtracting an array-like of ``DateOffset`` objects either raised (``np.array``, ``pd.Index``) or broadcast incorrectly (``pd.Series``) (:issue:`18849`) | |||
- Bug in :class:`Series` floor-division where operating on a scalar ``timedelta`` raises an exception (:issue:`18846`) | |||
|
|||
- Bug in :class:`Series`` with ``dtype='timedelta64[ns]`` where addition or subtraction of ``TimedeltaIndex`` had results cast to ``dtype='int64'`` (:issue:`17250`) | |||
- Bug in :class:`TimedeltaIndex` where multiplication or division by a ``Series`` would return a ``TimedeltaIndex`` instead of a ``Series`` (issue:`18963`) |
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 think you meant #19042?
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, thanks.
pandas/core/indexes/base.py
Outdated
if (isinstance(other, ABCSeries) and | ||
self.dtype == "timedelta64[ns]"): | ||
# GH#19042 | ||
return NotImplemented |
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.
Explain why you're doing this in a comment.
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'll expand the comment. This actually needs to be done for all Index classes because the problem is wide-spread, but I really want to avoid scope creep.
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.
Fair enough. I agree that we should try to keep the scope well-defined, though I might consider adding tests that you can xfail
for now and patch in a follow-up (if you can add / make tests generic enough to apply to all Index classes).
@jbrockmendel : Triple threat PR, very nice! 👍 |
Codecov Report
@@ Coverage Diff @@
## master #19044 +/- ##
=========================================
Coverage ? 91.53%
=========================================
Files ? 148
Lines ? 48691
Branches ? 0
=========================================
Hits ? 44569
Misses ? 4122
Partials ? 0
Continue to review full report at Codecov.
|
Hello @jbrockmendel! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on January 05, 2018 at 16:45 Hours UTC |
pandas/core/indexes/base.py
Outdated
@@ -4020,6 +4020,11 @@ def _add_numeric_methods_binary(cls): | |||
|
|||
def _make_evaluate_binop(op, opstr, reversed=False, constructor=Index): | |||
def _evaluate_numeric_binop(self, other): | |||
if (isinstance(other, ABCSeries) and |
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 don't like this at all. either let's remove this for now (and the corresponding test) or simplemente this by an override in the appopriate subclass.
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.
Removing this for now.
Overriding in subclass is a PITA b/c TimedeltaIndex._add_numeric_methods() is called below the definition of TimedeltaIndex and will override any __mul__
or __div__
methods we put in the class itself. So to override we need to implement it outside the class and pin it on after the call to add_numeric_methods. Since this is among my least favorite patterns, I'm punting on it.
pandas/core/ops.py
Outdated
@@ -775,6 +775,12 @@ def wrapper(left, right, name=name, na_op=na_op): | |||
res_name = left.name | |||
|
|||
result = wrap_results(safe_na_op(lvalues, rvalues)) | |||
try: |
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 do this in _construct_result and simply pass in name = res_name or getattr(result, 'name', None)
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.
Good call.
pandas/tests/indexes/test_numeric.py
Outdated
@@ -114,6 +114,22 @@ def test_numeric_compat(self): | |||
result = idx**2.0 | |||
tm.assert_index_equal(result, expected) | |||
|
|||
@pytest.mark.xfail(reason="Index._add_numeric_methods_binary does not " |
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 there an issue number ? I don't actually like adding a lot of xfails, if its only 1 ok
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.
Yah, 19042. I'm removing this test.
pandas/core/indexes/timedeltas.py
Outdated
@@ -912,6 +915,22 @@ def delete(self, loc): | |||
TimedeltaIndex._add_datetimelike_methods() | |||
|
|||
|
|||
def _override_tdi_arith_methods(): | |||
# GH#19042 |
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 rather just not do this now. remove.
pandas/core/ops.py
Outdated
return left._constructor(result, index=index, name=name, dtype=dtype) | ||
out = left._constructor(result, index=index, name=name, dtype=dtype) | ||
|
||
# If `result` has a non-None name and name is None, we need to override. |
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 make this a doc-string instead
doc/source/whatsnew/v0.23.0.txt
Outdated
@@ -308,7 +308,10 @@ Conversion | |||
- Bug in :class:`DatetimeIndex` where adding or subtracting an array-like of ``DateOffset`` objects either raised (``np.array``, ``pd.Index``) or broadcast incorrectly (``pd.Series``) (:issue:`18849`) | |||
- Bug in :class:`Series` floor-division where operating on a scalar ``timedelta`` raises an exception (:issue:`18846`) | |||
- Bug in :class:`Index` constructor with ``dtype=CategoricalDtype(...)`` where ``categories`` and ``ordered`` are not maintained (issue:`19032`) | |||
|
|||
- Bug in :class:`Series`` with ``dtype='timedelta64[ns]`` where addition or subtraction of ``TimedeltaIndex`` had results cast to ``dtype='int64'`` (:issue:`17250`) | |||
- Bug in :class:`TimedeltaIndex` where division by a ``Series`` would return a ``TimedeltaIndex`` instead of a ``Series`` (issue:`19042`) |
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 crossed this out is that correct?
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.
The original PR fixed both TimedeltaIndex.__mul__
and TimedeltaIndex.__div__
. Then we narrowed the scope so it only fixed __div__
.
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, so is that issue closed by this PR? (you cross it out i the header of the PR)
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.
Correct, #19042 is not fully closed by this PR.
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, let's close #19042 with this, and pls create a new issue for the residual. (and ref this PR)
pandas/core/ops.py
Outdated
the name argument is None, then passing name to the constructor will | ||
not be enough; we still need to override the name attribute. | ||
""" | ||
out = left._constructor(result, index=index, name=name, dtype=dtype) |
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.
let's just not pass the name at all to the constructor then (and just set as you are doing)
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.
Sounds good.
rebase and lgtm. |
ping |
thanks @jbrockmendel |
Fix a couple others caused by failing to return NotImplemented or to override names correctly.
closes #17250
xref #19042
closes #19043
git diff upstream/master -u -- "*.py" | flake8 --diff