Skip to content

Fixed typing on IntervalIndex functions #174

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 2 commits into from
Jul 31, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
64 changes: 34 additions & 30 deletions pandas-stubs/core/indexes/interval.pyi
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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: ...
Expand All @@ -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): ...
Expand Down
36 changes: 36 additions & 0 deletions tests/test_interval_index.py
Original file line number Diff line number Diff line change
@@ -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)