Skip to content

tolerance in Series and DataFrame.reindex does not like Timedelta #1307

@cmp0xff

Description

@cmp0xff

Describe the bug

In practice and in the documentation, tolerance in reindex of Series and DataFrame supports Timedelta, which is not recognised in the stubs.

To Reproduce

Minimal reproducible script

import pandas as pd

sr = pd.Series([1, 2], pd.to_datetime(["2023-01-01", "2023-01-02"]))
sr.reindex(index=pd.to_datetime(["2023-01-02", "2023-01-03"]), method="ffill", tolerance=pd.Timedelta("1D"))

df = sr.to_frame()
df.reindex(index=pd.to_datetime(["2023-01-02", "2023-01-03"]), method="ffill", tolerance=pd.Timedelta("1D"))

Indicate which type checker you are using

Both

Show the error message received from that type checker while checking your example.

mypy

attempt.py:4: error: Argument "tolerance" to "reindex" of "Series" has incompatible type "Timedelta"; expected "float | None"  [arg-type]
attempt.py:7: error: Argument "tolerance" to "reindex" of "DataFrame" has incompatible type "Timedelta"; expected "float | None"  [arg-type]

pyright

  attempt.py:4:90 - error: Argument of type "Timedelta" cannot be assigned to parameter "tolerance" of type "float | None" in function "reindex"
    Type "Timedelta" is not assignable to type "float | None"
      "Timedelta" is not assignable to "float"
      "Timedelta" is not assignable to "None" (reportArgumentType)
  attempt.py:7:90 - error: Argument of type "Timedelta" cannot be assigned to parameter "tolerance" of type "float | None" in function "reindex"
    Type "Timedelta" is not assignable to type "float | None"
      "Timedelta" is not assignable to "float"
      "Timedelta" is not assignable to "None" (reportArgumentType)
2 errors, 0 warnings, 0 informations

Please complete the following information:

OS

Windows

OS Version

11

python version

3.12.10

version of type checker

  • mypy: 1.17.0
  • pyright: 1.1.403

version of installed pandas-stubs

Current main branch

Additional context

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions