@@ -100,14 +100,13 @@ def take_nd(
100
100
return arr .take (indexer , fill_value = fill_value , allow_fill = allow_fill )
101
101
102
102
arr = np .asarray (arr )
103
- return _take_nd_ndarray (arr , indexer , axis , None , fill_value , allow_fill )
103
+ return _take_nd_ndarray (arr , indexer , axis , fill_value , allow_fill )
104
104
105
105
106
106
def _take_nd_ndarray (
107
107
arr : np .ndarray ,
108
108
indexer ,
109
109
axis : int ,
110
- out : np .ndarray | None ,
111
110
fill_value ,
112
111
allow_fill : bool ,
113
112
) -> np .ndarray :
@@ -119,7 +118,7 @@ def _take_nd_ndarray(
119
118
indexer = ensure_platform_int (indexer )
120
119
121
120
indexer , dtype , fill_value , mask_info = _take_preprocess_indexer_and_fill_value (
122
- arr , indexer , out , fill_value , allow_fill
121
+ arr , indexer , fill_value , allow_fill
123
122
)
124
123
125
124
flip_order = False
@@ -129,23 +128,20 @@ def _take_nd_ndarray(
129
128
if flip_order :
130
129
arr = arr .T
131
130
axis = arr .ndim - axis - 1
132
- if out is not None :
133
- out = out .T
134
131
135
132
# at this point, it's guaranteed that dtype can hold both the arr values
136
133
# and the fill_value
137
- if out is None :
138
- out_shape_ = list (arr .shape )
139
- out_shape_ [axis ] = len (indexer )
140
- out_shape = tuple (out_shape_ )
141
- if arr .flags .f_contiguous and axis == arr .ndim - 1 :
142
- # minor tweak that can make an order-of-magnitude difference
143
- # for dataframes initialized directly from 2-d ndarrays
144
- # (s.t. df.values is c-contiguous and df._mgr.blocks[0] is its
145
- # f-contiguous transpose)
146
- out = np .empty (out_shape , dtype = dtype , order = "F" )
147
- else :
148
- out = np .empty (out_shape , dtype = dtype )
134
+ out_shape_ = list (arr .shape )
135
+ out_shape_ [axis ] = len (indexer )
136
+ out_shape = tuple (out_shape_ )
137
+ if arr .flags .f_contiguous and axis == arr .ndim - 1 :
138
+ # minor tweak that can make an order-of-magnitude difference
139
+ # for dataframes initialized directly from 2-d ndarrays
140
+ # (s.t. df.values is c-contiguous and df._mgr.blocks[0] is its
141
+ # f-contiguous transpose)
142
+ out = np .empty (out_shape , dtype = dtype , order = "F" )
143
+ else :
144
+ out = np .empty (out_shape , dtype = dtype )
149
145
150
146
func = _get_take_nd_function (
151
147
arr .ndim , arr .dtype , out .dtype , axis = axis , mask_info = mask_info
@@ -190,7 +186,7 @@ def take_1d(
190
186
return arr .take (indexer )
191
187
192
188
indexer , dtype , fill_value , mask_info = _take_preprocess_indexer_and_fill_value (
193
- arr , indexer , None , fill_value , True
189
+ arr , indexer , fill_value , True
194
190
)
195
191
196
192
# at this point, it's guaranteed that dtype can hold both the arr values
@@ -516,7 +512,6 @@ def _take_2d_multi_object(
516
512
def _take_preprocess_indexer_and_fill_value (
517
513
arr : np .ndarray ,
518
514
indexer : np .ndarray ,
519
- out : np .ndarray | None ,
520
515
fill_value ,
521
516
allow_fill : bool ,
522
517
):
@@ -534,10 +529,7 @@ def _take_preprocess_indexer_and_fill_value(
534
529
mask = indexer == - 1
535
530
needs_masking = mask .any ()
536
531
mask_info = mask , needs_masking
537
- if needs_masking :
538
- if out is not None and out .dtype != dtype :
539
- raise TypeError ("Incompatible type for fill_value" )
540
- else :
532
+ if not needs_masking :
541
533
# if not, then depromote, set fill_value to dummy
542
534
# (it won't be used but we don't want the cython code
543
535
# to crash when trying to cast it to dtype)
0 commit comments