From 4ea006ec4f8ddaf805c197ede3592fe17eed9a82 Mon Sep 17 00:00:00 2001 From: Brock Date: Wed, 27 Jan 2021 17:46:48 -0800 Subject: [PATCH] REF: dont pass fill-value in get_reindexed_values --- pandas/core/algorithms.py | 21 ++++++++++++++++++++- pandas/core/internals/concat.py | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index ae7e8191fc482..6c5c5d5d5b75e 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -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 @@ -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) diff --git a/pandas/core/internals/concat.py b/pandas/core/internals/concat.py index 0b611bfdb1f10..166b630378c5a 100644 --- a/pandas/core/internals/concat.py +++ b/pandas/core/internals/concat.py @@ -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