Repository: pandas-dev/pandas-stubs (language: python)

Issue:
`pd.Timedelta` should also accept `float` values
The `value` parameter of `Timedelta` currently has the following type-hint:
https://github.com/pandas-dev/pandas-stubs/blob/f71224c6211ff436424be614ba47f494f64c4618/pandas-stubs/_libs/tslibs/timedeltas.pyi#L105

I think it should also accept float, so that type checkers won't complain on following code snippet:
```python
import pandas as pd
pd.Timedelta(3.5, 'hours')
```

```
Argument of type "float" cannot be assigned to parameter "value" of type "str | int | Timedelta | timedelta | timedelta64" in function "__new__"
  Type "float" is not assignable to type "str | int | Timedelta | timedelta | timedelta64"
    "float" is not assignable to "str"
    "float" is not assignable to "int"
    "float" is not assignable to "Timedelta"
    "float" is not assignable to "timedelta"
    "float" is not assignable to "timedelta64"
Pylance[reportArgumentType](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportArgumentType)
```

`pd.Timedelta` should also accept `float` values
The `value` parameter of `Timedelta` currently has the following type-hint:
https://github.com/pandas-dev/pandas-stubs/blob/f71224c6211ff436424be614ba47f494f64c4618/pandas-stubs/_libs/tslibs/timedeltas.pyi#L105

I think it should also accept float, so that type checkers won't complain on following code snippet:
```python
import pandas as pd
pd.Timedelta(3.5, 'hours')
```

```
Argument of type "float" cannot be assigned to parameter "value" of type "str | int | Timedelta | timedelta | timedelta64" in function "__new__"
  Type "float" is not assignable to type "str | int | Timedelta | timedelta | timedelta64"
    "float" is not assignable to "str"
    "float" is not assignable to "int"
    "float" is not assignable to "Timedelta"
    "float" is not assignable to "timedelta"
    "float" is not assignable to "timedelta64"
Pylance[reportArgumentType](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportArgumentType)
```



Discussion / hints:
Thanks for the report.  The docs at https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Timedelta.html#pandas.Timedelta have the same issue, so can you raise an issue there as well?

PR with tests welcome.
https://github.com/pandas-dev/pandas/issues/60044
Thanks for the report.  The docs at https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Timedelta.html#pandas.Timedelta have the same issue, so can you raise an issue there as well?

PR with tests welcome.
https://github.com/pandas-dev/pandas/issues/60044

Fix patch:
diff --git a/pandas-stubs/_libs/tslibs/timedeltas.pyi b/pandas-stubs/_libs/tslibs/timedeltas.pyi
index b0f9bdf0..081f11e9 100644
--- a/pandas-stubs/_libs/tslibs/timedeltas.pyi
+++ b/pandas-stubs/_libs/tslibs/timedeltas.pyi
@@ -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 = ...,


Test patch:
diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py
index 9722c314..c38d832a 100644
--- a/tests/test_timefuncs.py
+++ b/tests/test_timefuncs.py
@@ -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)