Skip to content

Commit 8278971

Browse files
jbrockmendelJulianWgs
authored andcommitted
PERF: remove unused out kwd from take functions (pandas-dev#40934)
1 parent c38b897 commit 8278971

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

pandas/core/array_algos/take.py

+15-23
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,13 @@ def take_nd(
100100
return arr.take(indexer, fill_value=fill_value, allow_fill=allow_fill)
101101

102102
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)
104104

105105

106106
def _take_nd_ndarray(
107107
arr: np.ndarray,
108108
indexer,
109109
axis: int,
110-
out: np.ndarray | None,
111110
fill_value,
112111
allow_fill: bool,
113112
) -> np.ndarray:
@@ -119,7 +118,7 @@ def _take_nd_ndarray(
119118
indexer = ensure_platform_int(indexer)
120119

121120
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
123122
)
124123

125124
flip_order = False
@@ -129,23 +128,20 @@ def _take_nd_ndarray(
129128
if flip_order:
130129
arr = arr.T
131130
axis = arr.ndim - axis - 1
132-
if out is not None:
133-
out = out.T
134131

135132
# at this point, it's guaranteed that dtype can hold both the arr values
136133
# 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)
149145

150146
func = _get_take_nd_function(
151147
arr.ndim, arr.dtype, out.dtype, axis=axis, mask_info=mask_info
@@ -190,7 +186,7 @@ def take_1d(
190186
return arr.take(indexer)
191187

192188
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
194190
)
195191

196192
# at this point, it's guaranteed that dtype can hold both the arr values
@@ -516,7 +512,6 @@ def _take_2d_multi_object(
516512
def _take_preprocess_indexer_and_fill_value(
517513
arr: np.ndarray,
518514
indexer: np.ndarray,
519-
out: np.ndarray | None,
520515
fill_value,
521516
allow_fill: bool,
522517
):
@@ -534,10 +529,7 @@ def _take_preprocess_indexer_and_fill_value(
534529
mask = indexer == -1
535530
needs_masking = mask.any()
536531
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:
541533
# if not, then depromote, set fill_value to dummy
542534
# (it won't be used but we don't want the cython code
543535
# to crash when trying to cast it to dtype)

0 commit comments

Comments
 (0)