Skip to content

Commit cedafab

Browse files
committed
remove np.ndarray
1 parent a38eb85 commit cedafab

File tree

8 files changed

+114
-175
lines changed

8 files changed

+114
-175
lines changed

pandas-stubs/_typing.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ TimeNonexistent: TypeAlias = (
784784
DropKeep: TypeAlias = Literal["first", "last", False]
785785
CorrelationMethod: TypeAlias = (
786786
Literal["pearson", "kendall", "spearman"]
787-
| Callable[[np.ndarray, np.ndarray], float]
787+
| Callable[[np.typing.NDArray[Any], np.typing.NDArray[Any]], float]
788788
)
789789
AlignJoin: TypeAlias = Literal["outer", "inner", "left", "right"]
790790
DtypeBackend: TypeAlias = Literal["pyarrow", "numpy_nullable"]
@@ -858,6 +858,7 @@ ShapeT = TypeVar("ShapeT", bound=tuple[int, ...], default=tuple[Any, ...])
858858
np_ndarray: TypeAlias = np.ndarray[ShapeT, np.dtype[GenericT]]
859859
# Numpy arrays with known shape (Do not use as argument types, only as return types)
860860
np_1darray: TypeAlias = np.ndarray[tuple[int], np.dtype[GenericT]]
861+
np_1darray_bool: TypeAlias = np_1darray[np.bool]
861862
np_1darray_int64: TypeAlias = np_1darray[np.int64]
862863
np_1darray_float: TypeAlias = np_1darray[np.floating]
863864

pandas-stubs/core/indexers.pyi

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
from typing import Any
22

3-
import numpy as np
43
from numpy import typing as npt
54

65
from pandas._typing import (
76
AnyArrayLike,
8-
np_1darray,
97
)
108

119
def check_array_indexer(
1210
arrayArrayLike: AnyArrayLike, indexer: AnyArrayLike
13-
) -> np_1darray[np.bool_]: ...
11+
) -> np_1darray_bool: ...
1412

1513
class BaseIndexer:
1614
def __init__(

tests/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,31 @@
4545
UIntDtypeArg as UIntDtypeArg,
4646
VoidDtypeArg as VoidDtypeArg,
4747
np_1darray as np_1darray,
48+
np_1darray_bool as np_1darray_bool,
4849
np_1darray_float as np_1darray_float,
4950
np_1darray_int64 as np_1darray_int64,
5051
np_2darray as np_2darray,
5152
np_ndarray as np_ndarray,
5253
np_ndarray_bool as np_ndarray_bool,
54+
np_ndarray_dt as np_ndarray_dt,
5355
np_ndarray_int as np_ndarray_int,
56+
np_ndarray_td as np_ndarray_td,
5457
)
5558
else:
5659
_G = TypeVar("_G", bound=np.generic)
5760
_S = TypeVar("_S", bound=tuple[int, ...])
5861
# Separately define here so pytest works
5962
np_1darray: TypeAlias = np.ndarray[tuple[int], np.dtype[_G]]
63+
np_1darray_bool: TypeAlias = np_1darray[np.bool]
6064
np_1darray_int64: TypeAlias = np_1darray[np.int64]
6165
np_1darray_float: TypeAlias = np_1darray[np.floating]
6266
np_2darray: TypeAlias = np.ndarray[tuple[int, int], np.dtype[_G]]
6367
np_ndarray: TypeAlias = np.ndarray[_S, np.dtype[_G]]
6468
np_ndarray_bool: TypeAlias = npt.NDArray[np.bool_]
69+
np_ndarray_dt: TypeAlias = npt.NDArray[np.datetime64]
6570
np_ndarray_int: TypeAlias = npt.NDArray[np.signedinteger]
6671
np_ndarray_int64: TypeAlias = npt.NDArray[np.int64]
72+
np_ndarray_td: TypeAlias = npt.NDArray[np.timedelta64]
6773

6874
TYPE_CHECKING_INVALID_USAGE: Final = TYPE_CHECKING
6975
WINDOWS = os.name == "nt" or "cygwin" in platform.system().lower()

tests/extension/decimal/array.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import numbers
1212
import sys
1313
from typing import (
14-
TYPE_CHECKING,
1514
Any,
1615
cast,
1716
overload,
@@ -53,8 +52,11 @@
5352
pandas_dtype,
5453
)
5554

56-
if TYPE_CHECKING:
57-
from pandas._typing import np_1darray
55+
from tests import (
56+
np_1darray,
57+
np_1darray_bool,
58+
np_ndarray,
59+
)
5860

5961

6062
@register_extension_dtype
@@ -94,7 +96,7 @@ class DecimalArray(OpsMixin, ExtensionScalarOpsMixin, ExtensionArray):
9496

9597
def __init__(
9698
self,
97-
values: MutableSequence[decimal._DecimalNew] | np.ndarray | ExtensionArray,
99+
values: MutableSequence[decimal._DecimalNew] | np_ndarray | ExtensionArray,
98100
dtype: DecimalDtype | None = None,
99101
copy: bool = False,
100102
context: decimal.Context | None = None,
@@ -126,7 +128,7 @@ def dtype(self) -> DecimalDtype:
126128
@classmethod
127129
def _from_sequence(
128130
cls,
129-
scalars: list[decimal._DecimalNew] | np.ndarray | ExtensionArray,
131+
scalars: list[decimal._DecimalNew] | np_ndarray | ExtensionArray,
130132
dtype: DecimalDtype | None = None,
131133
copy: bool = False,
132134
) -> Self:
@@ -144,7 +146,7 @@ def _from_sequence_of_strings(
144146
@classmethod
145147
def _from_factorized(
146148
cls,
147-
values: list[decimal._DecimalNew] | np.ndarray | ExtensionArray,
149+
values: list[decimal._DecimalNew] | np_ndarray | ExtensionArray,
148150
original: Any,
149151
) -> Self:
150152
return cls(values)
@@ -157,7 +159,7 @@ def to_numpy(
157159
copy: bool = False,
158160
na_value: object = no_default,
159161
decimals: int | None = None,
160-
) -> np.ndarray:
162+
) -> np_ndarray:
161163
result = np.asarray(self, dtype=dtype)
162164
if decimals is not None:
163165
result = np.asarray([round(x, decimals) for x in result])
@@ -192,7 +194,7 @@ def reconstruct(
192194
decimal.Decimal
193195
| numbers.Number
194196
| list[decimal._DecimalNew]
195-
| np.ndarray
197+
| np_ndarray
196198
),
197199
) -> decimal.Decimal | numbers.Number | DecimalArray:
198200
if isinstance(x, (decimal.Decimal, numbers.Number)):
@@ -281,7 +283,7 @@ def nbytes(self) -> int:
281283
return n * sys.getsizeof(self[0])
282284
return 0
283285

284-
def isna(self) -> np_1darray[np.bool_]:
286+
def isna(self) -> np_1darray_bool:
285287
if sys.version_info < (3, 11):
286288
return np.array([x.is_nan() for x in self._data], bool) # type: ignore[return-value] # pyright: ignore[reportReturnType]
287289
return np.array([x.is_nan() for x in self._data], bool)
@@ -320,7 +322,7 @@ def _reduce(self, name: str, *, skipna: bool = True, **kwargs: Any) -> Any:
320322

321323
def _cmp_method(
322324
self, other: Any, op: Callable[[Self, ExtensionArray | list[Any]], bool]
323-
) -> np_1darray[np.bool_]:
325+
) -> np_1darray_bool:
324326
# For use with OpsMixin
325327
def convert_values(param: Any) -> ExtensionArray | list[Any]:
326328
if isinstance(param, ExtensionArray) or is_list_like(param):
@@ -337,9 +339,7 @@ def convert_values(param: Any) -> ExtensionArray | list[Any]:
337339
# a TypeError should be raised
338340
res = [op(a, b) for (a, b) in zip(lvalues, rvalues)]
339341

340-
return cast(
341-
np.ndarray[tuple[int], np.dtype[np.bool_]], np.asarray(res, dtype=bool)
342-
)
342+
return cast(np_1darray_bool, np.asarray(res, dtype=bool))
343343

344344
def value_counts(self, dropna: bool = True) -> Series:
345345
from pandas.core.algorithms import value_counts

0 commit comments

Comments
 (0)