Skip to content

Commit a9c803c

Browse files
authored
REF: dont pass fill-value in get_reindexed_values (#39446)
1 parent 51e7e4d commit a9c803c

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

pandas/core/algorithms.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -1658,8 +1658,25 @@ def take(arr, indices, axis: int = 0, allow_fill: bool = False, fill_value=None)
16581658
return result
16591659

16601660

1661+
# TODO: can we de-duplicate with something in dtypes.missing?
1662+
def _get_default_fill_value(dtype, fill_value):
1663+
if fill_value is lib.no_default:
1664+
if is_extension_array_dtype(dtype):
1665+
fill_value = dtype.na_value
1666+
elif dtype.kind in ["m", "M"]:
1667+
fill_value = dtype.type("NaT")
1668+
else:
1669+
fill_value = np.nan
1670+
return fill_value
1671+
1672+
16611673
def take_nd(
1662-
arr, indexer, axis: int = 0, out=None, fill_value=np.nan, allow_fill: bool = True
1674+
arr,
1675+
indexer,
1676+
axis: int = 0,
1677+
out=None,
1678+
fill_value=lib.no_default,
1679+
allow_fill: bool = True,
16631680
):
16641681
"""
16651682
Specialized Cython take which sets NaN values in one pass
@@ -1694,6 +1711,8 @@ def take_nd(
16941711
"""
16951712
mask_info = None
16961713

1714+
fill_value = _get_default_fill_value(arr.dtype, fill_value)
1715+
16971716
if isinstance(arr, ABCExtensionArray):
16981717
# Check for EA to catch DatetimeArray, TimedeltaArray
16991718
return arr.take(indexer, fill_value=fill_value, allow_fill=allow_fill)

pandas/core/internals/concat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def get_reindexed_values(self, empty_dtype: DtypeObj, upcasted_na) -> ArrayLike:
323323

324324
else:
325325
for ax, indexer in self.indexers.items():
326-
values = algos.take_nd(values, indexer, axis=ax, fill_value=fill_value)
326+
values = algos.take_nd(values, indexer, axis=ax)
327327

328328
return values
329329

0 commit comments

Comments
 (0)