1313 algos as libalgos ,
1414 lib ,
1515)
16- from pandas ._typing import ArrayLike
16+ from pandas ._typing import (
17+ ArrayLike ,
18+ npt ,
19+ )
1720
1821from pandas .core .dtypes .cast import maybe_promote
1922from pandas .core .dtypes .common import (
@@ -110,7 +113,7 @@ def take_nd(
110113
111114def _take_nd_ndarray (
112115 arr : np .ndarray ,
113- indexer ,
116+ indexer : npt . NDArray [ np . intp ] | None ,
114117 axis : int ,
115118 fill_value ,
116119 allow_fill : bool ,
@@ -122,7 +125,7 @@ def _take_nd_ndarray(
122125 else :
123126 indexer = ensure_platform_int (indexer )
124127
125- indexer , dtype , fill_value , mask_info = _take_preprocess_indexer_and_fill_value (
128+ dtype , fill_value , mask_info = _take_preprocess_indexer_and_fill_value (
126129 arr , indexer , fill_value , allow_fill
127130 )
128131
@@ -160,30 +163,32 @@ def _take_nd_ndarray(
160163
161164def take_1d (
162165 arr : ArrayLike ,
163- indexer : np .ndarray ,
166+ indexer : npt . NDArray [ np .intp ] ,
164167 fill_value = None ,
165168 allow_fill : bool = True ,
166169) -> ArrayLike :
167170 """
168171 Specialized version for 1D arrays. Differences compared to `take_nd`:
169172
170173 - Assumes input array has already been converted to numpy array / EA
171- - Assumes indexer is already guaranteed to be int64 dtype ndarray
174+ - Assumes indexer is already guaranteed to be intp dtype ndarray
172175 - Only works for 1D arrays
173176
174177 To ensure the lowest possible overhead.
175178
176179 Note: similarly to `take_nd`, this function assumes that the indexer is
177180 a valid(ated) indexer with no out of bound indices.
178181 """
182+ indexer = ensure_platform_int (indexer )
183+
179184 if not isinstance (arr , np .ndarray ):
180185 # ExtensionArray -> dispatch to their method
181186 return arr .take (indexer , fill_value = fill_value , allow_fill = allow_fill )
182187
183188 if not allow_fill :
184189 return arr .take (indexer )
185190
186- indexer , dtype , fill_value , mask_info = _take_preprocess_indexer_and_fill_value (
191+ dtype , fill_value , mask_info = _take_preprocess_indexer_and_fill_value (
187192 arr , indexer , fill_value , True
188193 )
189194
@@ -200,7 +205,9 @@ def take_1d(
200205
201206
202207def take_2d_multi (
203- arr : np .ndarray , indexer : tuple [np .ndarray , np .ndarray ], fill_value = np .nan
208+ arr : np .ndarray ,
209+ indexer : tuple [npt .NDArray [np .intp ], npt .NDArray [np .intp ]],
210+ fill_value = np .nan ,
204211) -> np .ndarray :
205212 """
206213 Specialized Cython take which sets NaN values in one pass.
@@ -249,6 +256,7 @@ def take_2d_multi(
249256 if func is not None :
250257 func (arr , indexer , out = out , fill_value = fill_value )
251258 else :
259+ # test_reindex_multi
252260 _take_2d_multi_object (
253261 arr , indexer , out , fill_value = fill_value , mask_info = mask_info
254262 )
@@ -457,7 +465,7 @@ def wrapper(
457465
458466def _take_nd_object (
459467 arr : np .ndarray ,
460- indexer : np . ndarray , # np.ndarray [np.intp]
468+ indexer : npt . NDArray [np .intp ],
461469 out : np .ndarray ,
462470 axis : int ,
463471 fill_value ,
@@ -480,7 +488,7 @@ def _take_nd_object(
480488
481489def _take_2d_multi_object (
482490 arr : np .ndarray ,
483- indexer : tuple [np .ndarray , np .ndarray ],
491+ indexer : tuple [npt . NDArray [ np .intp ], npt . NDArray [ np .intp ] ],
484492 out : np .ndarray ,
485493 fill_value ,
486494 mask_info ,
@@ -509,7 +517,7 @@ def _take_2d_multi_object(
509517
510518def _take_preprocess_indexer_and_fill_value (
511519 arr : np .ndarray ,
512- indexer : np .ndarray ,
520+ indexer : npt . NDArray [ np .intp ] ,
513521 fill_value ,
514522 allow_fill : bool ,
515523):
@@ -533,5 +541,4 @@ def _take_preprocess_indexer_and_fill_value(
533541 # to crash when trying to cast it to dtype)
534542 dtype , fill_value = arr .dtype , arr .dtype .type ()
535543
536- indexer = ensure_platform_int (indexer )
537- return indexer , dtype , fill_value , mask_info
544+ return dtype , fill_value , mask_info
0 commit comments