Skip to content

TYP: generate_regular_range #47295

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
merged 2 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 9 additions & 8 deletions pandas/core/arrays/_ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
Timestamp,
iNaT,
)
from pandas._typing import npt


def generate_regular_range(
start: Timestamp | Timedelta,
end: Timestamp | Timedelta,
periods: int,
start: Timestamp | Timedelta | None,
end: Timestamp | Timedelta | None,
periods: int | None,
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Mind updating the docstring below for this argument that periods can be None?

Copy link
Member Author

Choose a reason for hiding this comment

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

green and updated the doc-string

freq: BaseOffset,
):
) -> npt.NDArray[np.intp]:
"""
Generate a range of dates or timestamps with the spans between dates
described by the given `freq` DateOffset.
Expand All @@ -32,7 +33,7 @@ def generate_regular_range(
First point of produced date range.
end : Timedelta, Timestamp or None
Last point of produced date range.
periods : int
periods : int or None
Number of periods in produced date range.
freq : Tick
Describes space between dates in produced date range.
Expand All @@ -45,15 +46,15 @@ def generate_regular_range(
iend = end.value if end is not None else None
stride = freq.nanos

if periods is None:
if periods is None and istart is not None and iend is not None:
b = istart
# cannot just use e = Timestamp(end) + 1 because arange breaks when
# stride is too large, see GH10887
e = b + (iend - b) // stride * stride + stride // 2 + 1
elif istart is not None:
elif istart is not None and periods is not None:
b = istart
e = _generate_range_overflow_safe(b, periods, stride, side="start")
elif iend is not None:
elif iend is not None and periods is not None:
e = iend + stride
b = _generate_range_overflow_safe(e, periods, stride, side="end")
else:
Expand Down
4 changes: 3 additions & 1 deletion pyright_reportGeneralTypeIssues.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
[
# exclude tests
"pandas/tests",
# exclude vendored files
"pandas/io/clipboard",
"pandas/util/version",
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

# and all files that currently don't pass
"pandas/_config/config.py",
"pandas/core/algorithms.py",
"pandas/core/apply.py",
"pandas/core/array_algos/take.py",
"pandas/core/arrays/_mixins.py",
"pandas/core/arrays/_ranges.py",
"pandas/core/arrays/arrow/array.py",
"pandas/core/arrays/base.py",
"pandas/core/arrays/boolean.py",
Expand Down