Skip to content

ENH: arithmetic between DatetimeArray and list #62353

@cmp0xff

Description

@cmp0xff

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

I wish Pandas could implement arithmetic operations for DatetimeArrays and Python native lists.

Feature Description

I wish the following code could run.

from datetime import datetime
import pandas as pd

arr = pd.to_datetime(["2020-01-01", "2020-01-02"]).array
assert isinstance(arr, pd.arrays.DatetimeArray)

arr - [datetime(2019, 12, 31), datetime(2020, 1, 1)]  # TypeError: unsupported operand type(s) for -: 'DatetimeArray' and 'list'

Alternative Solutions

from datetime import datetime
import pandas as pd

arr = pd.to_datetime(["2020-01-01", "2020-01-02"]).array
assert isinstance(arr, pd.arrays.DatetimeArray)

arr - pd.to_datetime([datetime(2019, 12, 31), datetime(2020, 1, 1)]).array

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementNeeds TriageIssue that has not been reviewed by a pandas team memberNumeric OperationsArithmetic, Comparison, and Logical operations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions