Skip to content

API: Series/DTIndex arithmetic with timedeltas and offsets should work the same #4134

Closed
@hayd

Description

@hayd

from stack: http://stackoverflow.com/questions/17491446/wrong-result-from-timedelta-operation/17492653#17492653

In [101]: rng = pd.date_range('2013', '2014')

In [102]: rng
Out[102]:
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-07-05 00:00:00, ..., 2014-07-05 00:00:00]
Length: 366, Freq: D, Timezone: None

In [103]: s = pd.Series(rng)

These work

In [105]: rng - pd.offsets.Hour(1)
Out[105]:
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-07-04 23:00:00, ..., 2014-07-04 23:00:00]
Length: 366, Freq: D, Timezone: None

In [106]: s - np.timedelta64(100000000)

but the other way around doesn't.

In [107]: rng - np.timedelta64(100000000)
NotImplementedError:

In [108]: s - pd.offsets.Hour(1)
ValueError: cannot operate on a series with out a rhs of a series/ndarray of type datetime64[ns] or a timedelta

cc #3009.

Metadata

Metadata

Assignees

No one assigned

    Labels

    API DesignDtype ConversionsUnexpected or buggy dtype conversionsIndexingRelated to indexing on series/frames, not to indexes themselvesTimedeltaTimedelta data type

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions