Skip to content

Commit 9023943

Browse files
committed
get_indexer
1 parent 56ba992 commit 9023943

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

pandas-stubs/core/indexes/base.pyi

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ from pandas._typing import (
6666
S2_NSDT,
6767
T_COMPLEX,
6868
AnyAll,
69+
AnyArrayLike,
6970
ArrayLike,
7071
AxesData,
7172
CategoryDtypeArg,
@@ -418,8 +419,12 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
418419
) -> Self: ...
419420
def get_loc(self, key: Label) -> int | slice | np_1darray[np.bool]: ...
420421
def get_indexer(
421-
self, target, method: ReindexMethod | None = ..., limit=..., tolerance=...
422-
): ...
422+
self,
423+
target: Index,
424+
method: ReindexMethod | None = None,
425+
limit: int | None = None,
426+
tolerance: Scalar | AnyArrayLike | Sequence[Scalar] | None = None,
427+
) -> np_1darray[np.intp]: ...
423428
def reindex(
424429
self,
425430
target,

pandas-stubs/core/indexes/range.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ class RangeIndex(_IndexSubclassBase[int, np.int64]):
6262
) -> tuple[np_1darray[np.intp], RangeIndex]: ...
6363
@property
6464
def size(self) -> int: ...
65-
def __floordiv__(
65+
# Base class returns `Self`, but for `RangeIndex` that's not true.
66+
def __floordiv__( # type: ignore[override]
6667
self, other: float | Sequence[float] | Index[int] | Index[float]
6768
) -> Index[int]: ...
6869
def all(self, *args: Any, **kwargs: Any) -> bool: ...

tests/indexes/test_rangeindex.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from __future__ import annotations
22

3+
import numpy as np
34
import pandas as pd
45
from typing_extensions import (
56
assert_type,
67
)
78

89
from tests import (
910
check,
11+
np_1darray,
1012
)
1113

1214

@@ -39,8 +41,16 @@ def test_rangeindex_equals() -> None:
3941

4042

4143
def test_rangeindex_tolist() -> None:
42-
ri = pd.RangeIndex(3)
44+
ri = pd.RangeIndex.from_range(range(3))
4345
check(
4446
assert_type(ri.tolist(), list[int]),
4547
list[int],
4648
)
49+
50+
51+
def test_rangeindex_get_indexer() -> None:
52+
ri = pd.RangeIndex.from_range(range(3))
53+
check(
54+
assert_type(ri.get_indexer(ri), np_1darray[np.intp]),
55+
np_1darray[np.intp],
56+
)

0 commit comments

Comments
 (0)