Skip to content
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

Return NotImpelmented for arith ops with object-dtype Index subclasses #31109

Closed
TomAugspurger opened this issue Jan 17, 2020 · 2 comments · Fixed by #31136
Closed

Return NotImpelmented for arith ops with object-dtype Index subclasses #31109

TomAugspurger opened this issue Jan 17, 2020 · 2 comments · Fixed by #31136
Labels
Blocker Blocking issue or pull request for an upcoming release Numeric Operations Arithmetic, Comparison, and Logical operations
Milestone

Comments

@TomAugspurger
Copy link
Contributor

This change in 1.0 impacted xarray

 In [22]: import xarray as xr

In [23]: import pandas as pd

In [24]: idx = pd.timedelta_range("1D", periods=5, freq="D")

In [25]: a = xr.cftime_range("2000", periods=5)

In [26]: idx + a
/Users/taugspurger/sandbox/pandas/pandas/core/arrays/datetimelike.py:1204: PerformanceWarning: Adding/subtracting array of DateOffsets to TimedeltaArray not vectorized
  PerformanceWarning,
Out[26]:
Index([2000-01-02 00:00:00, 2000-01-04 00:00:00, 2000-01-06 00:00:00,
       2000-01-08 00:00:00, 2000-01-10 00:00:00],
      dtype='object')

In [27]: a + idx
Out[27]:
CFTimeIndex([2000-01-02 00:00:00, 2000-01-04 00:00:00, 2000-01-06 00:00:00,
             2000-01-08 00:00:00, 2000-01-10 00:00:00],
            dtype='object')

cc @jbrockmendel @dcherian. Brock suggested checking type(other), and returning NotImplemented for index subclasses we don't know about, to give the subclass a chance to take over the op.

@TomAugspurger TomAugspurger added this to the 1.0.0 milestone Jan 17, 2020
@TomAugspurger TomAugspurger added Blocker Blocking issue or pull request for an upcoming release Numeric Operations Arithmetic, Comparison, and Logical operations labels Jan 17, 2020
@jbrockmendel
Copy link
Member

Should we try to get a short-term fix in for 1.0?

@TomAugspurger
Copy link
Contributor Author

Yep, I think so.

TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue Jan 19, 2020
This changes index ops to check the *type* of the argument in index
ops, rather than just the dtype. This lets index subclasses take control
of binary ops when they know better what the result should be.

Closes pandas-dev#31109
TomAugspurger added a commit that referenced this issue Jan 28, 2020
* COMPAT: Return NotImplemented for subclassing

This changes index ops to check the *type* of the argument in index
ops, rather than just the dtype. This lets index subclasses take control
of binary ops when they know better what the result should be.

Closes #31109
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocker Blocking issue or pull request for an upcoming release Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants