Skip to content

DateOffsets should allow element-wise addition to Series #10699

Closed
@jorisvandenbossche

Description

@jorisvandenbossche

Adding a DateOffset works for single Timestamps and for DatetimeIndex, but fails on a Series:

In [132]: s = pd.Series(pd.date_range('2012-01-01', periods=3))

In [133]: s
Out[133]:
0   2012-01-01
1   2012-01-02
2   2012-01-03
dtype: datetime64[ns]

In [134]: s[0] + pd.DateOffset(months=2)
Out[134]: Timestamp('2012-03-01 00:00:00')

In [135]: pd.DatetimeIndex(s) + pd.DateOffset(months=2)
Out[135]: DatetimeIndex(['2012-03-01', '2012-03-02', '2012-03-03'], dtype='datetime64[ns]', freq='D', tz=None)

In [136]: s + pd.DateOffset(months=2)
---------------------------------------------------------------------------
TypeError: cannot use a non-absolute DateOffset in datetime/timedelta operations
 [<DateOffset: kwds={'months': 2}>]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions