Skip to content

Series[offsets] + Series[datetime64] fails #19211

Closed
@jbrockmendel

Description

@jbrockmendel
ser = pd.Series([pd.Timestamp('2000-1-1'), pd.Timestamp('2000-2-1')])
other = pd.Series([pd.offsets.DateOffset(years=1), pd.offsets.MonthEnd()])

>>> ser + other
0   2001-01-01
1   2000-02-29
dtype: datetime64[ns]

>>> other + ser
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pandas/core/ops.py", line 698, in wrapper
    result = wrap_results(safe_na_op(lvalues, rvalues))
  File "pandas/core/ops.py", line 665, in safe_na_op
    lambda x: op(x, rvalues))
  File "pandas/_libs/algos_common_helper.pxi", line 1212, in pandas._libs.algos.arrmap_object
    result[i] = func(index[i])
  File "pandas/core/ops.py", line 665, in <lambda>
    lambda x: op(x, rvalues))
  File "pandas/tseries/offsets.py", line 352, in __add__
    return self.apply(other)
  File "pandas/tseries/offsets.py", line 77, in wrapper
    result = func(self, other)
  File "pandas/tseries/offsets.py", line 212, in apply
    other = other + self._offset
TypeError: ufunc add cannot use operands with types dtype('<M8[ns]') and dtype('O')

pd.Index(other) + ser is OK, as is other + pd.DatetimeIndex(ser)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions