Skip to content

DOC: Fixed PR06 docstrings errors in pandas.timedelta_range #28719

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

Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from datetime import datetime
import warnings

from typing import Optional

import numpy as np

from pandas._libs import NaT, Timedelta, index as libindex, join as libjoin, lib
Expand Down Expand Up @@ -709,25 +711,30 @@ def _is_convertible_to_index(other):


def timedelta_range(
start=None, end=None, periods=None, freq=None, name=None, closed=None
):
start: Optional[str] = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from the docstring this str or timedelta-like.

I would only add types for the pure str, boolean or int types here and do the more complex typing in a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that, when I use pure str and int types, mypy fails with this error:

pandas/core/indexes/timedeltas.py:711: error: Incompatible default for argument "start" (default has type "None", argument has type "str")
pandas/core/indexes/timedeltas.py:711: error: Incompatible default for argument "end" (default has type "None", argument has type "str")
pandas/core/indexes/timedeltas.py:711: error: Incompatible default for argument "periods" (default has type "None", argument has type "int")
pandas/core/indexes/timedeltas.py:711: error: Incompatible default for argument "freq" (default has type "None", argument has type "str")
pandas/core/indexes/timedeltas.py:711: error: Incompatible default for argument "name" (default has type "None", argument has type "str")
pandas/core/indexes/timedeltas.py:711: error: Incompatible default for argument "closed" (default has type "None", argument has type "str")

which is why I've removed typing in my last commit. Thus, this PR only deals with the PR06 docs errors.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thus, this PR only deals with the PR06 docs errors.

no problem. lets keep typing separate for now.

end: Optional[str] = None,
periods: Optional[int] = None,
freq: Optional[str] = None,
name: Optional[str] = None,
closed: Optional[str] = None,
) -> TimedeltaIndex:
"""
Return a fixed frequency TimedeltaIndex, with day as the default
frequency.

Parameters
----------
start : string or timedelta-like, default None
start : str or timedelta-like, default None
Left bound for generating timedeltas
end : string or timedelta-like, default None
end : str or timedelta-like, default None
Right bound for generating timedeltas
periods : integer, default None
periods : int, default None
Number of periods to generate
freq : string or DateOffset, default 'D'
freq : str or DateOffset, default 'D'
Frequency strings can have multiples, e.g. '5H'
name : string, default None
name : str, default None
Name of the resulting TimedeltaIndex
closed : string, default None
closed : str, default None
Make the interval closed with respect to the given frequency to
the 'left', 'right', or both sides (None)

Expand Down