Skip to content

DEV: Error in main branch when subtracting a valid numpy timedelta from a Series of timestamps #54059

Closed
@Dr-Irv

Description

@Dr-Irv
import pandas as pd
import numpy as np
s1 = pd.Series(data=pd.date_range("1/1/2020", "2/1/2020"))
td = np.timedelta64(1, "M")
s1-td

With version 2.1.0.dev0+1159.gc126eeb392 and numpy 1.24.3, get the following error:

  File "C:\Code\pandas_dev\pandas\pandas\core\ops\common.py", line 85, in new_method
    return method(self, other)
  File "C:\Code\pandas_dev\pandas\pandas\core\arraylike.py", line 194, in __sub__
    return self._arith_method(other, operator.sub)
  File "C:\Code\pandas_dev\pandas\pandas\core\series.py", line 5735, in _arith_method
    return base.IndexOpsMixin._arith_method(self, other, op)
  File "C:\Code\pandas_dev\pandas\pandas\core\base.py", line 1342, in _arith_method
    rvalues = ops.maybe_prepare_scalar_for_op(rvalues, lvalues.shape)
  File "C:\Code\pandas_dev\pandas\pandas\core\ops\array_ops.py", line 575, in maybe_prepare_scalar_for_op
    return Timedelta(obj)
  File "timedeltas.pyx", line 1846, in pandas._libs.tslibs.timedeltas.Timedelta.__new__
ValueError:  cannot construct a Timedelta from a unit M

Tagging @mcgeestocks since last commit related to this code made by him and @mroeschke since he approved the PR #53421

Metadata

Metadata

Assignees

Labels

Error ReportingIncorrect or improved errors from pandasTimedeltaTimedelta data typeTimestamppd.Timestamp and associated methods

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions