Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bemoody opened this issue Mar 29, 2023 · 3 comments · Fixed by #670
Closed

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

bemoody opened this issue Mar 29, 2023 · 3 comments · Fixed by #670

Comments

@bemoody
Copy link

bemoody commented Mar 29, 2023

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.)

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Mar 29, 2023

We generally follow a policy that the stubs follow what is documented for pandas.

So before we change the stubs, we should get agreement from the pandas maintainers that Timedelta and timedelta are supposed to be allowed with timedelta_range() and interval_range(). Can you open a doc issue in the pandas project there and cross-reference to here, so we can track that?

@bemoody
Copy link
Author

bemoody commented Apr 4, 2023

The documentation has now been updated (thanks to @allisonkwan for the quick response.)

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Apr 4, 2023

The documentation has now been updated (thanks to @allisonkwan for the quick response.)

Great. Now someone can do a PR to update the stubs here for date_range(), interval_range(), bdate_range(), and timedelta_range(), with appropriate tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants