Skip to content

Commit c171840

Browse files
GH1095 Add list of string to to_timedelta
1 parent 3f42941 commit c171840

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

pandas-stubs/core/tools/timedeltas.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def to_timedelta(
3333
def to_timedelta(
3434
arg: (
3535
SequenceNotStr
36-
| Sequence[float | timedelta]
36+
| Sequence[float | timedelta | str]
3737
| tuple[str | float | timedelta, ...]
3838
| range
3939
| ArrayLike

tests/test_timefuncs.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,3 +1425,10 @@ def test_DatetimeIndex_sub_timedelta() -> None:
14251425
),
14261426
pd.DatetimeIndex,
14271427
)
1428+
1429+
1430+
def test_datetimeindex_as_unit() -> None:
1431+
"""Test that we can pass a list of str for `to_timedelta` GH1095."""
1432+
tdelta_idx = pd.to_timedelta(["1 day 3 min 2 us 42 ns"])
1433+
check(assert_type(tdelta_idx, pd.TimedeltaIndex), pd.TimedeltaIndex)
1434+
check(assert_type(tdelta_idx.as_unit("s"), pd.TimedeltaIndex), pd.TimedeltaIndex)

0 commit comments

Comments
 (0)