Skip to content

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

Merged
merged 10 commits into from
Jan 5, 2018
Merged

Conversation

jbrockmendel
Copy link
Member

@jbrockmendel jbrockmendel commented Jan 3, 2018

Fix a couple others caused by failing to return NotImplemented or to override names correctly.

closes #17250
xref #19042
closes #19043

  • tests added / passed
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

fix a couple others caused by failing to return NotImplemented or to override names correctly
@@ -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`)
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks.

if (isinstance(other, ABCSeries) and
self.dtype == "timedelta64[ns]"):
# GH#19042
return NotImplemented
Copy link
Member

@gfyoung gfyoung Jan 3, 2018

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.

Copy link
Member Author

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.

Copy link
Member

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).

@gfyoung
Copy link
Member

gfyoung commented Jan 3, 2018

@jbrockmendel : Triple threat PR, very nice! 👍

@gfyoung gfyoung added Bug Timedelta Timedelta data type Datetime Datetime data dtype labels Jan 3, 2018
@codecov
Copy link

codecov bot commented Jan 3, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@856c92b). Click here to learn what that means.
The diff coverage is 83.33%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #19044   +/-   ##
=========================================
  Coverage          ?   91.53%           
=========================================
  Files             ?      148           
  Lines             ?    48691           
  Branches          ?        0           
=========================================
  Hits              ?    44569           
  Misses            ?     4122           
  Partials          ?        0
Flag Coverage Δ
#multiple 89.9% <83.33%> (?)
#single 41.62% <66.66%> (?)
Impacted Files Coverage Δ
pandas/core/ops.py 91.89% <100%> (ø)
pandas/core/indexes/timedeltas.py 90.92% <50%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 856c92b...10296e8. Read the comment docs.

@pep8speaks
Copy link

pep8speaks commented Jan 3, 2018

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

@@ -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
Copy link
Contributor

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.

Copy link
Member Author

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.

@@ -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:
Copy link
Contributor

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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call.

@@ -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 "
Copy link
Contributor

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

Copy link
Member Author

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.

@@ -912,6 +915,22 @@ def delete(self, loc):
TimedeltaIndex._add_datetimelike_methods()


def _override_tdi_arith_methods():
# GH#19042
Copy link
Contributor

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.

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.
Copy link
Contributor

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

@@ -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`)
Copy link
Contributor

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?

Copy link
Member Author

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__.

Copy link
Contributor

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)

Copy link
Member Author

@jbrockmendel jbrockmendel Jan 4, 2018

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.

Copy link
Contributor

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)

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)
Copy link
Contributor

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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

@jreback jreback added this to the 0.23.0 milestone Jan 5, 2018
@jreback
Copy link
Contributor

jreback commented Jan 5, 2018

rebase and lgtm.

@jbrockmendel
Copy link
Member Author

ping

@jreback jreback merged commit f2d8db1 into pandas-dev:master Jan 5, 2018
@jreback
Copy link
Contributor

jreback commented Jan 5, 2018

thanks @jbrockmendel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype Timedelta Timedelta data type
Projects
None yet
4 participants