Skip to content

Commit

Permalink
Switch to_timedelta argument type from list to Sequence (#959)
Browse files Browse the repository at this point in the history
* GH 956 Allowing sequence type in to_timedelta

* GH 956 PR feedback

* GH 956 PR feedback

* GH 956 PR feedback

* Update tests/test_timefuncs.py

Co-authored-by: Irv Lustig <[email protected]>

* Fixing lint issue

---------

Co-authored-by: Irv Lustig <[email protected]>
  • Loading branch information
loicdiridollou and Dr-Irv authored Jul 16, 2024
1 parent 71b2555 commit 48ca4b0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
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

0 comments on commit 48ca4b0

Please sign in to comment.