Skip to content

REF: dont pass fill_value to algos.take_nd from internals.concat #39446

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 2 commits into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
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
21 changes: 20 additions & 1 deletion pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1658,8 +1658,25 @@ def take(arr, indices, axis: int = 0, allow_fill: bool = False, fill_value=None)
return result


# TODO: can we de-duplicate with something in dtypes.missing?
def _get_default_fill_value(dtype, fill_value):
if fill_value is lib.no_default:
if is_extension_array_dtype(dtype):
fill_value = dtype.na_value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

na_value_for_dtype

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats what i thought too, but its behavior is slightly different

elif dtype.kind in ["m", "M"]:
fill_value = dtype.type("NaT")
else:
fill_value = np.nan
return fill_value


def take_nd(
arr, indexer, axis: int = 0, out=None, fill_value=np.nan, allow_fill: bool = True
arr,
indexer,
axis: int = 0,
out=None,
fill_value=lib.no_default,
allow_fill: bool = True,
):
"""
Specialized Cython take which sets NaN values in one pass
Expand Down Expand Up @@ -1694,6 +1711,8 @@ def take_nd(
"""
mask_info = None

fill_value = _get_default_fill_value(arr.dtype, fill_value)

if isinstance(arr, ABCExtensionArray):
# Check for EA to catch DatetimeArray, TimedeltaArray
return arr.take(indexer, fill_value=fill_value, allow_fill=allow_fill)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def get_reindexed_values(self, empty_dtype: DtypeObj, upcasted_na) -> ArrayLike:

else:
for ax, indexer in self.indexers.items():
values = algos.take_nd(values, indexer, axis=ax, fill_value=fill_value)
values = algos.take_nd(values, indexer, axis=ax)

return values

Expand Down