Skip to content

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

Closed
@TomAugspurger

Description

@TomAugspurger

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BlockerBlocking issue or pull request for an upcoming releaseNumeric OperationsArithmetic, Comparison, and Logical operations

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions