Skip to content

timedelta_range or interval_range should accept Timedelta or timedelta as freq #600

Closed
@bemoody

Description

@bemoody

Describe the bug
The timedelta_range and interval_range functions should accept a pandas.Timedelta or datetime.timedelta object as the freq argument.

To Reproduce
Example:

import pandas

def foo(step: float):
    return pandas.timedelta_range(
        start=pandas.Timedelta(0),
        periods=10,
        freq=pandas.Timedelta(seconds=step),
    )

Using mypy foo.py:

foo.py:7: error: Argument "freq" to "timedelta_range" has incompatible type "Timedelta"; expected "Union[str, DateOffset, None]"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

Please complete the following information:

  • OS: Debian 11.6
  • Python: 3.9.2
  • mypy: 1.1.1
  • pandas: 1.5.3
  • pandas-stubs: 1.5.3.230321

Additional context
#223 mentions date_range and bdate_range.

pandas-dev/pandas#48631 updates the documentation for date_range, bdate_range, and interval_range.

#322 updates the stubs for date_range and bdate_range.

However, using Timedelta or timedelta with timedelta_range seems to work as well. (I'm not sure I fully understand the difference between Timedelta and DateOffset, but I don't see why a Timedelta shouldn't be accepted here.)

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