-
-
Notifications
You must be signed in to change notification settings - Fork 147
GH1327 Add overloead for date_range and timedelta_range #1333
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
Changes from 2 commits
2a99f70
f26b710
584e288
9bf345a
56be8d4
fc35578
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,11 +102,45 @@ class DatetimeIndex( | |
self, periods: int = 1, freq: DateOffset | Timedelta | str | None = None | ||
) -> Self: ... | ||
|
||
@overload | ||
def date_range( | ||
end: str | DateAndDatetimeLike, | ||
periods: int, | ||
freq: str | timedelta | Timedelta | BaseOffset | None = None, | ||
tz: TimeZones = None, | ||
normalize: bool = False, | ||
name: Hashable | None = None, | ||
inclusive: IntervalClosedType = "both", | ||
unit: TimeUnit | None = None, | ||
) -> DatetimeIndex: ... | ||
@overload | ||
def date_range( | ||
start: str | DateAndDatetimeLike, | ||
periods: int, | ||
freq: str | timedelta | Timedelta | BaseOffset | None = None, | ||
tz: TimeZones = None, | ||
normalize: bool = False, | ||
name: Hashable | None = None, | ||
inclusive: IntervalClosedType = "both", | ||
unit: TimeUnit | None = None, | ||
) -> DatetimeIndex: ... | ||
@overload | ||
def date_range( | ||
start: str | DateAndDatetimeLike | None, | ||
end: str | DateAndDatetimeLike | None, | ||
freq: str | timedelta | Timedelta | BaseOffset | None = None, | ||
tz: TimeZones = None, | ||
normalize: bool = False, | ||
name: Hashable | None = None, | ||
inclusive: IntervalClosedType = "both", | ||
unit: TimeUnit | None = None, | ||
) -> DatetimeIndex: ... | ||
@overload | ||
def date_range( | ||
start: str | DateAndDatetimeLike | None = None, | ||
end: str | DateAndDatetimeLike | None = None, | ||
periods: int | None = None, | ||
freq: str | timedelta | Timedelta | BaseOffset = "D", | ||
start: str | DateAndDatetimeLike, | ||
end: str | DateAndDatetimeLike, | ||
periods: int, | ||
freq: None = None, | ||
tz: TimeZones = None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see the point here of having separate overloads. Also, you need to put back the default values. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the original goal was to only allow three out of the four values among |
||
normalize: bool = False, | ||
name: Hashable | None = None, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,10 +79,51 @@ class TimedeltaIndex( | |
def to_series(self, index=..., name: Hashable = ...) -> TimedeltaSeries: ... | ||
def shift(self, periods: int = 1, freq=...) -> Self: ... | ||
|
||
@overload | ||
def timedelta_range( | ||
start: TimedeltaConvertibleTypes | None = None, | ||
end: TimedeltaConvertibleTypes | None = None, | ||
periods: int | None = None, | ||
start: TimedeltaConvertibleTypes, | ||
end: TimedeltaConvertibleTypes, | ||
periods: int, | ||
freq: None = None, | ||
name: Hashable | None = None, | ||
closed: Literal["left", "right"] | None = None, | ||
*, | ||
unit: None | str = ..., | ||
) -> TimedeltaIndex: ... | ||
@overload | ||
def timedelta_range( | ||
start: TimedeltaConvertibleTypes, | ||
periods: int, | ||
freq: None = None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you're going to have a similar issue in terms of mixing positional vs. keyword arguments. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is now fixed. |
||
name: Hashable | None = None, | ||
closed: Literal["left", "right"] | None = None, | ||
*, | ||
unit: None | str = ..., | ||
) -> TimedeltaIndex: ... | ||
@overload | ||
def timedelta_range( | ||
start: TimedeltaConvertibleTypes, | ||
periods: int, | ||
freq: str | DateOffset | Timedelta | dt.timedelta | None = None, | ||
name: Hashable | None = None, | ||
closed: Literal["left", "right"] | None = None, | ||
*, | ||
unit: None | str = ..., | ||
) -> TimedeltaIndex: ... | ||
@overload | ||
def timedelta_range( | ||
start: TimedeltaConvertibleTypes, | ||
end: TimedeltaConvertibleTypes, | ||
freq: str | DateOffset | Timedelta | dt.timedelta | None = None, | ||
name: Hashable | None = None, | ||
closed: Literal["left", "right"] | None = None, | ||
*, | ||
unit: None | str = ..., | ||
) -> TimedeltaIndex: ... | ||
@overload | ||
def timedelta_range( | ||
end: TimedeltaConvertibleTypes, | ||
periods: int, | ||
freq: str | DateOffset | Timedelta | dt.timedelta | None = None, | ||
name: Hashable | None = None, | ||
closed: Literal["left", "right"] | None = None, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1563,6 +1563,13 @@ def test_timedelta_range() -> None: | |
pd.TimedeltaIndex, | ||
) | ||
|
||
if TYPE_CHECKING_INVALID_USAGE: | ||
day1 = pd.Timedelta(1, unit="D") | ||
day10 = pd.Timedelta(10, unit="D") | ||
pd.timedelta_range( | ||
day1, day10, periods=10, freq="D" # type: ignore[call-overload] # pyright: ignore[reportArgumentType] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Passing all four should be banned |
||
) | ||
|
||
|
||
def test_dateoffset_freqstr() -> None: | ||
offset = DateOffset(minutes=10) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These would only work if the arguments are keyword arguments, so I think you need to put an asterisk (
*
) right after the opening parenthesis.