Skip to content

IntervalIndex is a subclass of Index #542

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 3 commits into from
Feb 17, 2023
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
2 changes: 1 addition & 1 deletion pandas-stubs/core/algorithms.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def unique(values: PeriodIndex) -> PeriodIndex: ... # type: ignore[misc] # pyri
@overload
def unique(values: CategoricalIndex) -> CategoricalIndex: ... # type: ignore[misc]
@overload
def unique(values: IntervalIndex[IntervalT]) -> IntervalIndex[IntervalT]: ...
def unique(values: IntervalIndex[IntervalT]) -> IntervalIndex[IntervalT]: ... # type: ignore[misc]
@overload
def unique(values: Index) -> np.ndarray: ...
@overload
Expand Down
19 changes: 10 additions & 9 deletions pandas-stubs/core/indexes/interval.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ from typing import (
import numpy as np
import pandas as pd
from pandas import Index
from pandas.core.indexes.extension import ExtensionIndex
from pandas.core.series import (
Series,
TimedeltaSeries,
Expand Down Expand Up @@ -65,7 +66,7 @@ _EdgesTimedelta: TypeAlias = (
_TimestampLike: TypeAlias = pd.Timestamp | np.datetime64 | dt.datetime
_TimedeltaLike: TypeAlias = pd.Timedelta | np.timedelta64 | dt.timedelta

class IntervalIndex(IntervalMixin, Generic[IntervalT]):
class IntervalIndex(ExtensionIndex, IntervalMixin, Generic[IntervalT]):
closed: IntervalClosedType

def __new__(
Expand Down Expand Up @@ -248,7 +249,7 @@ class IntervalIndex(IntervalMixin, Generic[IntervalT]):
@property
def length(self) -> Index: ...
def get_value(self, series: ABCSeries, key): ...
@overload
@overload # type: ignore[override]
def __getitem__(
self,
idx: slice
Expand All @@ -262,37 +263,37 @@ class IntervalIndex(IntervalMixin, Generic[IntervalT]):
def __getitem__(self, idx: int) -> IntervalT: ...
@property
def is_all_dates(self) -> bool: ...
@overload
@overload # type: ignore[override]
def __gt__(
self, other: IntervalT | IntervalIndex[IntervalT]
) -> np_ndarray_bool: ...
@overload
def __gt__(self, other: pd.Series[IntervalT]) -> pd.Series[bool]: ...
@overload
@overload # type: ignore[override]
def __ge__(
self, other: IntervalT | IntervalIndex[IntervalT]
) -> np_ndarray_bool: ...
@overload
def __ge__(self, other: pd.Series[IntervalT]) -> pd.Series[bool]: ...
@overload
@overload # type: ignore[override]
def __le__(
self, other: IntervalT | IntervalIndex[IntervalT]
) -> np_ndarray_bool: ...
@overload
def __le__(self, other: pd.Series[IntervalT]) -> pd.Series[bool]: ...
@overload
@overload # type: ignore[override]
def __lt__(
self, other: IntervalT | IntervalIndex[IntervalT]
) -> np_ndarray_bool: ...
@overload
def __lt__(self, other: pd.Series[IntervalT]) -> bool: ...
@overload
def __lt__(self, other: pd.Series[IntervalT]) -> pd.Series[bool]: ...
@overload # type: ignore[override]
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]: ...
@overload
@overload # type: ignore[override]
def __ne__(self, other: IntervalT | IntervalIndex[IntervalT]) -> np_ndarray_bool: ... # type: ignore[misc]
@overload
def __ne__(self, other: pd.Series[IntervalT]) -> pd.Series[bool]: ... # type: ignore[misc]
Expand Down
11 changes: 11 additions & 0 deletions tests/test_interval_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ def test_to_tuples() -> None:
check(assert_type(ind, pd.Index), pd.Index, tuple)


def test_subclass() -> None:
assert issubclass(pd.IntervalIndex, pd.Index)

def index(test: pd.Index) -> None:
...

interval_index = pd.IntervalIndex.from_tuples([(0, 1), (1, 2)])
index(interval_index)
pd.DataFrame({"a": [1, 2]}, interval_index)


def test_is_overlapping() -> None:
ind = pd.IntervalIndex.from_tuples([(0, 2), (1, 3), (4, 5)])
check(assert_type(ind.is_overlapping, bool), bool)
Expand Down