Skip to content

Commit 5365bfc

Browse files
committed
fixup insert
1 parent 0015e53 commit 5365bfc

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

pandas-stubs/core/arrays/categorical.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class Categorical(ExtensionArray):
110110
def take(
111111
self, indexer: TakeIndexer, *, allow_fill: bool = ..., fill_value=...
112112
) -> Categorical: ...
113+
def __contains__(self, key) -> bool: ...
113114
@overload
114115
def __getitem__(self, key: ScalarIndexer) -> Any: ...
115116
@overload
@@ -120,6 +121,7 @@ class Categorical(ExtensionArray):
120121
def __setitem__(self, key, value) -> None: ...
121122
def min(self, *, skipna: bool = ...): ...
122123
def max(self, *, skipna: bool = ...): ...
124+
def unique(self): ...
123125
def equals(self, other): ...
124126
def describe(self): ...
125127
def repeat(self, repeats, axis=...): ...

pandas-stubs/core/indexes/base.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,9 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
524524
self, start: SliceType = None, end: SliceType = None, step: int | None = None
525525
): ...
526526
def delete(self, loc: int | AnyArrayLikeInt | Sequence[int]) -> Self: ...
527+
@overload
528+
def insert(self, loc: int, item: S1) -> Self: ...
529+
@overload
527530
def insert(self, loc: int, item: object) -> Index: ...
528531
def drop(self, labels, errors: IgnoreRaise = "raise") -> Self: ...
529532
@property

pandas-stubs/core/indexes/category.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@ class CategoricalIndex(ExtensionIndex[S1], accessor.PandasDelegate):
3737
def is_monotonic_increasing(self) -> bool: ...
3838
@property
3939
def is_monotonic_decreasing(self) -> bool: ...
40+
# `item` might be `S1` but not one of the categories, thus changing
41+
# the return type from `CategoricalIndex` to `Index`.
42+
def insert(self, loc: int, item: object) -> Index: ... # type: ignore[override]

tests/indexes/test_categoricalindex.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ def test_categoricalindex_unique() -> None:
2222

2323
def test_categoricalindex_reindex() -> None:
2424
ci = pd.CategoricalIndex(["a", "b"])
25-
reindexed = ci.reindex(["b", "c"])
26-
check(assert_type(reindexed[0], pd.Index), pd.Index)
27-
check(assert_type(reindexed[1], np_1darray[np.intp] | None), np_1darray)
25+
check(
26+
assert_type(ci.reindex([0, 1]), tuple[pd.Index, np_1darray[np.intp] | None]),
27+
tuple,
28+
)
2829

2930

3031
def test_categoricalindex_delete() -> None:

0 commit comments

Comments
 (0)