Skip to content

Commit 48ca4b0

Browse files
Switch to_timedelta argument type from list to Sequence (#959)
* 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]>
1 parent 71b2555 commit 48ca4b0

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

pandas-stubs/core/tools/timedeltas.pyi

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ from pandas._libs.tslibs.timedeltas import TimeDeltaUnitChoices
1414
from pandas._typing import (
1515
ArrayLike,
1616
RaiseCoerce,
17+
SequenceNotStr,
1718
)
1819

1920
@overload
@@ -31,8 +32,8 @@ def to_timedelta(
3132
@overload
3233
def to_timedelta(
3334
arg: (
34-
Sequence[float | timedelta]
35-
| list[str | float | timedelta]
35+
SequenceNotStr
36+
| Sequence[float | timedelta]
3637
| tuple[str | float | timedelta, ...]
3738
| range
3839
| ArrayLike

tests/test_timefuncs.py

+5
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ def test_timedelta_series_arithmetic() -> None:
140140
r4: pd.TimedeltaIndex = tds1 / 10.2
141141

142142

143+
def test_timedelta_series_string() -> None:
144+
seq_list = ["1 day"]
145+
check(assert_type(pd.to_timedelta(seq_list), pd.TimedeltaIndex), pd.TimedeltaIndex)
146+
147+
143148
def test_timestamp_timedelta_series_arithmetic() -> None:
144149
ts1 = pd.to_datetime(pd.Series(["2022-03-05", "2022-03-06"]))
145150
assert isinstance(ts1.iloc[0], pd.Timestamp)

0 commit comments

Comments
 (0)