Skip to content

Commit 1341968

Browse files
authored
maint: split Sequence[int] out from AnyArrayLikeInt (#1425)
* maint: split `Sequence[int]` out from `AnyArrayLikeInt` * add ndarray test * use npt.NDArray instead of 1d numpy array
1 parent 6bd43f9 commit 1341968

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

pandas-stubs/_typing.pyi

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ HashableT5 = TypeVar("HashableT5", bound=Hashable)
8686

8787
ArrayLike: TypeAlias = ExtensionArray | np.ndarray
8888
AnyArrayLike: TypeAlias = ArrayLike | Index | Series
89+
AnyArrayLikeInt: TypeAlias = (
90+
IntegerArray | Index[int] | Series[int] | npt.NDArray[np.integer]
91+
)
8992

9093
# list-like
9194

@@ -864,10 +867,6 @@ np_ndarray: TypeAlias = np.ndarray[ShapeT, np.dtype[GenericT]]
864867
np_1darray: TypeAlias = np.ndarray[tuple[int], np.dtype[GenericT]]
865868
np_2darray: TypeAlias = np.ndarray[tuple[int, int], np.dtype[GenericT]]
866869

867-
AnyArrayLikeInt: TypeAlias = (
868-
IntegerArray | Index[int] | Series[int] | np_1darray[np.integer] | Sequence[int]
869-
)
870-
871870
class SupportsDType(Protocol[GenericT_co]):
872871
@property
873872
def dtype(self) -> np.dtype[GenericT_co]: ...

pandas-stubs/core/arrays/base.pyi

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
from collections.abc import Iterator
1+
from collections.abc import (
2+
Iterator,
3+
Sequence,
4+
)
25
from typing import (
36
Any,
47
Literal,
@@ -58,7 +61,9 @@ class ExtensionArray:
5861
def unique(self) -> Self: ...
5962
def searchsorted(self, value, side: str = ..., sorter=...): ...
6063
def factorize(self, use_na_sentinel: bool = True) -> tuple[np_1darray, Self]: ...
61-
def repeat(self, repeats: int | AnyArrayLikeInt, axis: None = None) -> Self: ...
64+
def repeat(
65+
self, repeats: int | AnyArrayLikeInt | Sequence[int], axis: None = None
66+
) -> Self: ...
6267
def take(
6368
self,
6469
indexer: TakeIndexer,

tests/arrays/test_extension_array.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Test common ExtensionArray methods
2-
2+
import numpy as np
33
import pandas as pd
44
from pandas.core.arrays.integer import IntegerArray
55
from pandas.core.construction import array
@@ -14,6 +14,7 @@ def test_ea_common() -> None:
1414

1515
check(assert_type(arr.repeat(1), IntegerArray), IntegerArray)
1616
check(assert_type(arr.repeat(arr), IntegerArray), IntegerArray)
17+
check(assert_type(arr.repeat(np.array([1, 2, 3])), IntegerArray), IntegerArray)
1718
check(
1819
assert_type(arr.repeat(repeats=pd.Series([1, 2, 3])), IntegerArray),
1920
IntegerArray,

0 commit comments

Comments
 (0)