Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
42 changes: 38 additions & 4 deletions pandas-stubs/core/indexes/datetimes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Collaborator

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.

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,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

The 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 start, end, periods and freq according to the docs.
Although the freq argument is often not passed.

normalize: bool = False,
name: Hashable | None = None,
Expand Down
47 changes: 44 additions & 3 deletions pandas-stubs/core/indexes/timedeltas.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

The 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,
Expand Down
4 changes: 3 additions & 1 deletion tests/test_styler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from pandas._typing import Scalar

from tests import (
PD_LTE_23,
check,
ensure_clean,
)
Expand Down Expand Up @@ -141,7 +142,8 @@ def test_highlight_quantile() -> None:


def test_loader() -> None:
check(assert_type(DF.style.loader, PackageLoader), PackageLoader)
if PD_LTE_23:
check(assert_type(DF.style.loader, PackageLoader), PackageLoader)


def test_pipe() -> None:
Expand Down
7 changes: 7 additions & 0 deletions tests/test_timefuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Copy link
Member Author

Choose a reason for hiding this comment

The 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)
Expand Down
Loading