Skip to content

CLN: remove unused out kwd from take functions #40934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 15 additions & 23 deletions pandas/core/array_algos/take.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,13 @@ def take_nd(
return arr.take(indexer, fill_value=fill_value, allow_fill=allow_fill)

arr = np.asarray(arr)
return _take_nd_ndarray(arr, indexer, axis, None, fill_value, allow_fill)
return _take_nd_ndarray(arr, indexer, axis, fill_value, allow_fill)


def _take_nd_ndarray(
arr: np.ndarray,
indexer,
axis: int,
out: np.ndarray | None,
fill_value,
allow_fill: bool,
) -> np.ndarray:
Expand All @@ -119,7 +118,7 @@ def _take_nd_ndarray(
indexer = ensure_platform_int(indexer)

indexer, dtype, fill_value, mask_info = _take_preprocess_indexer_and_fill_value(
arr, indexer, out, fill_value, allow_fill
arr, indexer, fill_value, allow_fill
)

flip_order = False
Expand All @@ -129,23 +128,20 @@ def _take_nd_ndarray(
if flip_order:
arr = arr.T
axis = arr.ndim - axis - 1
if out is not None:
out = out.T

# at this point, it's guaranteed that dtype can hold both the arr values
# and the fill_value
if out is None:
out_shape_ = list(arr.shape)
out_shape_[axis] = len(indexer)
out_shape = tuple(out_shape_)
if arr.flags.f_contiguous and axis == arr.ndim - 1:
# minor tweak that can make an order-of-magnitude difference
# for dataframes initialized directly from 2-d ndarrays
# (s.t. df.values is c-contiguous and df._mgr.blocks[0] is its
# f-contiguous transpose)
out = np.empty(out_shape, dtype=dtype, order="F")
else:
out = np.empty(out_shape, dtype=dtype)
out_shape_ = list(arr.shape)
out_shape_[axis] = len(indexer)
out_shape = tuple(out_shape_)
if arr.flags.f_contiguous and axis == arr.ndim - 1:
# minor tweak that can make an order-of-magnitude difference
# for dataframes initialized directly from 2-d ndarrays
# (s.t. df.values is c-contiguous and df._mgr.blocks[0] is its
# f-contiguous transpose)
out = np.empty(out_shape, dtype=dtype, order="F")
else:
out = np.empty(out_shape, dtype=dtype)

func = _get_take_nd_function(
arr.ndim, arr.dtype, out.dtype, axis=axis, mask_info=mask_info
Expand Down Expand Up @@ -190,7 +186,7 @@ def take_1d(
return arr.take(indexer)

indexer, dtype, fill_value, mask_info = _take_preprocess_indexer_and_fill_value(
arr, indexer, None, fill_value, True
arr, indexer, fill_value, True
)

# at this point, it's guaranteed that dtype can hold both the arr values
Expand Down Expand Up @@ -516,7 +512,6 @@ def _take_2d_multi_object(
def _take_preprocess_indexer_and_fill_value(
arr: np.ndarray,
indexer: np.ndarray,
out: np.ndarray | None,
fill_value,
allow_fill: bool,
):
Expand All @@ -534,10 +529,7 @@ def _take_preprocess_indexer_and_fill_value(
mask = indexer == -1
needs_masking = mask.any()
mask_info = mask, needs_masking
if needs_masking:
if out is not None and out.dtype != dtype:
raise TypeError("Incompatible type for fill_value")
else:
if not needs_masking:
# if not, then depromote, set fill_value to dummy
# (it won't be used but we don't want the cython code
# to crash when trying to cast it to dtype)
Expand Down