Skip to content

pd.Timedelta should also accept float values #1015

@5j9

Description

@5j9

The value parameter of Timedelta currently has the following type-hint:

value: str | int | Timedelta | timedelta | np.timedelta64 = ...,

I think it should also accept float, so that type checkers won't complain on following code snippet:

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions