diff --git a/pandas-stubs/core/indexes/interval.pyi b/pandas-stubs/core/indexes/interval.pyi index ab052fe30..974720a98 100644 --- a/pandas-stubs/core/indexes/interval.pyi +++ b/pandas-stubs/core/indexes/interval.pyi @@ -1,13 +1,18 @@ +from typing import Hashable + import numpy as np -from pandas.core.indexes.base import Index from pandas.core.indexes.extension import ExtensionIndex from pandas._libs.interval import ( Interval as Interval, IntervalMixin as IntervalMixin, ) -from pandas._typing import DtypeArg +from pandas._typing import ( + DtypeArg, + IntervalClosedType, +) +from pandas.core.dtypes.dtypes import IntervalDtype as IntervalDtype from pandas.core.dtypes.generic import ABCSeries as ABCSeries class SetopCheck: @@ -19,38 +24,46 @@ class IntervalIndex(IntervalMixin, ExtensionIndex): def __new__( cls, data, - closed=..., - dtype=..., + closed: IntervalClosedType = ..., + dtype: IntervalDtype | None = ..., copy: bool = ..., - name=..., + name: Hashable = ..., verify_integrity: bool = ..., ): ... @classmethod def from_breaks( - cls, breaks, closed: str = ..., name=..., copy: bool = ..., dtype=... - ): ... + cls, + breaks, + closed: IntervalClosedType = ..., + name: Hashable = ..., + copy: bool = ..., + dtype: IntervalDtype | None = ..., + ) -> IntervalIndex: ... @classmethod def from_arrays( - cls, left, right, closed: str = ..., name=..., copy: bool = ..., dtype=... - ): ... + cls, + left, + right, + closed: IntervalClosedType = ..., + name: Hashable = ..., + copy: bool = ..., + dtype: IntervalDtype | None = ..., + ) -> IntervalIndex: ... @classmethod def from_tuples( - cls, data, closed: str = ..., name=..., copy: bool = ..., dtype=... - ): ... - def __contains__(self, key) -> bool: ... - def values(self): ... - def __array_wrap__(self, result, context=...): ... - def __reduce__(self): ... - def astype(self, dtype: DtypeArg, copy: bool = ...) -> Index: ... + cls, + data, + closed: IntervalClosedType = ..., + name: Hashable = ..., + copy: bool = ..., + dtype: IntervalDtype | None = ..., + ) -> IntervalIndex: ... + def astype(self, dtype: DtypeArg, copy: bool = ...) -> IntervalIndex: ... @property def inferred_type(self) -> str: ... def memory_usage(self, deep: bool = ...) -> int: ... - def is_monotonic(self) -> bool: ... - def is_monotonic_increasing(self) -> bool: ... - def is_monotonic_decreasing(self) -> bool: ... - def is_unique(self): ... @property - def is_overlapping(self): ... + def is_overlapping(self) -> bool: ... def get_loc( self, key, method: str | None = ..., tolerance=... ) -> int | slice | np.ndarray: ... @@ -65,15 +78,6 @@ class IntervalIndex(IntervalMixin, ExtensionIndex): self, targetArrayLike ) -> tuple[np.ndarray, np.ndarray]: ... def get_value(self, series: ABCSeries, key): ... - def where(self, cond, other=...): ... - def delete(self, loc): ... - def insert(self, loc, item): ... - def take( - self, indices, axis: int = ..., allow_fill: bool = ..., fill_value=..., **kwargs - ): ... - def __getitem__(self, value): ... - def argsort(self, *args, **kwargs): ... - def equals(self, other) -> bool: ... @property def is_all_dates(self) -> bool: ... def __lt__(self, other): ... diff --git a/tests/test_interval_index.py b/tests/test_interval_index.py new file mode 100644 index 000000000..ec26019b6 --- /dev/null +++ b/tests/test_interval_index.py @@ -0,0 +1,36 @@ +from __future__ import annotations + +import pandas as pd +from typing_extensions import assert_type + +from tests import check + + +def test_from_breaks() -> None: + ind1: pd.IntervalIndex = pd.IntervalIndex.from_breaks([0, 1, 2, 3], name="test") + ind2: pd.IntervalIndex = pd.IntervalIndex.from_breaks( + [0, 1, 2, 3], closed="right", name=123 + ) + + +def test_from_arrays() -> None: + ind1: pd.IntervalIndex = pd.IntervalIndex.from_arrays( + [0, 1, 2], [1, 2, 3], name="test" + ) + ind2: pd.IntervalIndex = pd.IntervalIndex.from_arrays( + [0, 1, 2], [1, 2, 3], closed="right", name=123 + ) + + +def test_from_tuples() -> None: + ind1: pd.IntervalIndex = pd.IntervalIndex.from_tuples( + [(0, 1), (1, 2), (2, 3)], name="test" + ) + ind2: pd.IntervalIndex = pd.IntervalIndex.from_tuples( + [(0, 1), (1, 2), (2, 3)], closed="right", name=123 + ) + + +def test_is_overlapping() -> None: + ind = pd.IntervalIndex.from_tuples([(0, 2), (1, 3), (4, 5)]) + check(assert_type(ind.is_overlapping, bool), bool)