Skip to content

Commit

Permalink
accept float values in pd.Timedelta (#1026)
Browse files Browse the repository at this point in the history
* allow float values in pd.Timedelta

closes #1015

* int is subtype of float
  • Loading branch information
5j9 authored Nov 4, 2024
1 parent fd3bc04 commit 44be1fc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pandas-stubs/_libs/tslibs/timedeltas.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class Timedelta(timedelta):
value: int
def __new__(
cls,
value: str | int | Timedelta | timedelta | np.timedelta64 = ...,
value: str | float | Timedelta | timedelta | np.timedelta64 = ...,
unit: TimeDeltaUnitChoices = ...,
*,
days: float | np.integer | np.floating = ...,
Expand Down
5 changes: 5 additions & 0 deletions tests/test_timefuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ def test_timedelta_series_arithmetic() -> None:
r4: pd.TimedeltaIndex = tds1 / 10.2


def test_timedelta_float_value() -> None:
# GH 1015
check(assert_type(pd.Timedelta(1.5, "h"), pd.Timedelta), pd.Timedelta)


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

0 comments on commit 44be1fc

Please sign in to comment.