Skip to content

Switch to_timedelta argument type from list to Sequence #956

@headtr1ck

Description

@headtr1ck

Describe the bug
to_timedelta uses a list of a union argument type.
This will raise false positive errors when passing a list of a single type because list is invariant.

To Reproduce

import pandas as pd

pd.to_timedelta(["1 day"])

produces:

error: Argument 1 to "to_timedelta" has incompatible type "list[str]"; expected "Union[Sequence[Union[float, timedelta]], list[Union[str, float, timedelta]], tuple[Union[str, float, timedelta], ...], range, Union[ExtensionArray, ndarray[Any, Any]], Index[Any]]" [arg-type]
note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
note: Consider using "Sequence" instead, which is covariant

Please complete the following information:

  • OS: Win
  • OS Version 10
  • python 3.9.7
  • version of type checker mypy 1.8.0
  • version of installed pandas-stubs 2.2.2.240603

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