Skip to content

Commit

Permalink
REF: dont pass fill-value in get_reindexed_values (#39446)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored Feb 1, 2021
1 parent 51e7e4d commit a9c803c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
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
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 @@ -323,7 +323,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

0 comments on commit a9c803c

Please sign in to comment.