Skip to content

ENH: Improve typing for Interval #391

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 16 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions pandas-stubs/_libs/interval.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -160,25 +160,25 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
@overload
def __gt__(self, other: Interval[_OrderableT]) -> bool: ...
@overload
def __gt__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ... # type: ignore[misc]
def __gt__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ...
@overload
def __gt__(self, other: Series[_OrderableT]) -> Series[bool]: ...
@overload
def __lt__(self, other: Interval[_OrderableT]) -> bool: ...
@overload
def __lt__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ... # type: ignore[misc]
def __lt__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ...
@overload
def __lt__(self, other: Series[_OrderableT]) -> Series[bool]: ...
@overload
def __ge__(self, other: Interval[_OrderableT]) -> bool: ...
@overload
def __ge__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ... # type: ignore[misc]
def __ge__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ...
@overload
def __ge__(self, other: Series[_OrderableT]) -> Series[bool]: ...
@overload
def __le__(self, other: Interval[_OrderableT]) -> bool: ...
@overload
def __le__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ... # type: ignore[misc]
def __le__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ...
@overload
def __eq__(self, other: Interval[_OrderableT]) -> bool: ... # type: ignore[misc]
@overload
Expand Down
28 changes: 20 additions & 8 deletions pandas-stubs/core/indexes/interval.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ from pandas.core.series import (
TimedeltaSeries,
TimestampSeries,
)
from typing_extensions import TypeAlias
from typing_extensions import (
Never,
TypeAlias,
)

from pandas._libs.interval import (
Interval as Interval,
Expand Down Expand Up @@ -259,31 +262,31 @@ class IntervalIndex(IntervalMixin, ExtensionIndex, Generic[IntervalT]):
@overload
def __gt__(self, other: pd.Series[IntervalT]) -> pd.Series[bool]: ... # type: ignore[misc]
@overload
def __gt__(self, other: object) -> Literal[False]: ...
def __gt__(self, other: object) -> Never: ...
@overload # type: ignore[override]
def __ge__(self, other: IntervalT | IntervalIndex[IntervalT]) -> np_ndarray_bool: ... # type: ignore[misc]
@overload
def __ge__(self, other: pd.Series[IntervalT]) -> pd.Series[bool]: ... # type: ignore[misc]
@overload
def __ge__(self, other: object) -> Literal[False]: ...
def __ge__(self, other: object) -> Never: ...
@overload # type: ignore[override]
def __le__(self, other: IntervalT | IntervalIndex[IntervalT]) -> np_ndarray_bool: ... # type: ignore[misc]
@overload
def __le__(self, other: pd.Series[IntervalT]) -> pd.Series[bool]: ... # type: ignore[misc]
@overload
def __le__(self, other: object) -> Literal[False]: ...
def __le__(self, other: object) -> Never: ...
@overload # type: ignore[override]
def __lt__(self, other: IntervalT | IntervalIndex[IntervalT]) -> np_ndarray_bool: ... # type: ignore[misc]
@overload
def __lt__(self, other: pd.Series[IntervalT]) -> bool: ... # type: ignore[misc]
@overload
def __lt__(self, other: object) -> Literal[False]: ...
@overload # type: ignore[override]
def __lt__(self, other: object) -> Never: ...
@overload
def __eq__(self, other: IntervalT | IntervalIndex[IntervalT]) -> np_ndarray_bool: ... # type: ignore[misc]
@overload
def __eq__(self, other: pd.Series[IntervalT]) -> pd.Series[bool]: ... # type: ignore[misc]
@overload
def __eq__(self, other: object) -> Literal[False]: ...
def __eq__(self, other: object) -> Never: ...
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should remain Literal[False], because it is always valid code to do equality against another object.

@overload # type: ignore[override]
def __ne__(self, other: IntervalT | IntervalIndex[IntervalT]) -> np_ndarray_bool: ... # type: ignore[misc]
@overload
Expand Down Expand Up @@ -383,6 +386,15 @@ def interval_range(
closed: IntervalClosedType = ...,
) -> IntervalIndex[Interval[pd.Timestamp]]: ...
@overload
def interval_range(
start: _TimedeltaLike,
end: _TimedeltaLike = ...,
periods: int | None = ...,
freq: str | BaseOffset | None = ...,
name: Hashable = ...,
closed: IntervalClosedType = ...,
) -> IntervalIndex[Interval[pd.Timedelta]]: ...
@overload
def interval_range(
*,
start: None = ...,
Expand All @@ -391,7 +403,7 @@ def interval_range(
freq: str | BaseOffset | None = ...,
name: Hashable = ...,
closed: IntervalClosedType = ...,
) -> IntervalIndex[Interval[pd.Timestamp]]: ...
) -> IntervalIndex[Interval[pd.Timedelta]]: ...
@overload
def interval_range(
start: _TimedeltaLike,
Expand Down
Loading