Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to_timedelta argument type from list to Sequence #959

Merged
merged 6 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pandas-stubs/core/tools/timedeltas.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ from pandas._libs.tslibs.timedeltas import TimeDeltaUnitChoices
from pandas._typing import (
ArrayLike,
RaiseCoerce,
SequenceNotStr,
)

@overload
Expand All @@ -31,8 +32,8 @@ def to_timedelta(
@overload
def to_timedelta(
arg: (
Sequence[float | timedelta]
| list[str | float | timedelta]
SequenceNotStr
| Sequence[float | timedelta]
| tuple[str | float | timedelta, ...]
| range
| ArrayLike
Expand Down
5 changes: 5 additions & 0 deletions tests/test_timefuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ def test_timedelta_series_arithmetic() -> None:
r4: pd.TimedeltaIndex = tds1 / 10.2


def test_timedelta_series_string() -> None:
seq_list = ["1 day"]
check(assert_type(pd.to_timedelta(seq_list), pd.TimedeltaIndex), pd.TimedeltaIndex)


def test_timestamp_timedelta_series_arithmetic() -> None:
ts1 = pd.to_datetime(pd.Series(["2022-03-05", "2022-03-06"]))
assert isinstance(ts1.iloc[0], pd.Timestamp)
Expand Down
Loading