diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index 75434fcc2b40d..fc0a5375b5d75 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -7,7 +7,7 @@ from pandas._libs import tslib, lib from pandas._libs.tslib import iNaT -from pandas.compat import string_types, text_type, PY3 +from pandas.compat import string_types, text_type, PY3, _default_fill_value from .common import (_ensure_object, is_bool, is_integer, is_float, is_complex, is_datetimetz, is_categorical_dtype, is_datetimelike, @@ -255,6 +255,8 @@ def changeit(): def maybe_promote(dtype, fill_value=np.nan): + if fill_value is _default_fill_value: + fill_value = np.nan # if we passed an array here, determine the fill value by dtype if isinstance(fill_value, np.ndarray): diff --git a/pandas/core/generic.py b/pandas/core/generic.py index ba6cfddbc452b..ca53ad44a733a 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -7263,6 +7263,9 @@ def _align_frame(self, other, join='outer', axis=None, level=None, clidx, cridx = None, None is_series = isinstance(self, ABCSeries) + if fill_value is _default_fill_value: + # XXX: per-column? + fill_value = np.nan if axis is None or axis == 0: if not self.index.equals(other.index): diff --git a/pandas/core/internals.py b/pandas/core/internals.py index 59813c2a24bfd..0534308cb4857 100644 --- a/pandas/core/internals.py +++ b/pandas/core/internals.py @@ -4417,9 +4417,15 @@ def reindex_indexer(self, new_axis, indexer, axis, fill_value=None, else: if fill_value is None: fill_value = _default_fill_value - new_blocks = [blk.take_nd(indexer, axis=axis, fill_tuple=( - fill_value if fill_value is not _default_fill_value else blk.fill_value,)) - for blk in self.blocks] + + new_blocks = [] + for blk in self.blocks: + if fill_value is not _default_fill_value: + fill_tuple = (fill_value,) + else: + fill_tuple = (blk.fill_value,) + new_blocks = [blk.take_nd(indexer, axis=axis, fill_tuple=fill_tuple) + for blk in self.blocks] new_axes = list(self.axes) new_axes[axis] = new_axis diff --git a/pandas/core/series.py b/pandas/core/series.py index 886567500ce71..348a77fd8d9cc 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3217,7 +3217,7 @@ def _reindex_indexer(self, new_index, indexer, copy): return self from pandas.core.dtypes.missing import na_value_for_dtype - fill_value = na_value_for_dtype(self.dtype) + fill_value = na_value_for_dtype(self.dtype, compat=False) new_values = algorithms.take(self._values, indexer, fill_value=fill_value) return self._constructor(new_values, index=new_index) diff --git a/pandas/core/sparse/frame.py b/pandas/core/sparse/frame.py index 2cefbea722098..b282450efb037 100644 --- a/pandas/core/sparse/frame.py +++ b/pandas/core/sparse/frame.py @@ -6,7 +6,7 @@ # pylint: disable=E1101,E1103,W0231,E0202 import warnings -from pandas.compat import lmap +from pandas.compat import lmap, _default_fill_value from pandas import compat import numpy as np @@ -690,7 +690,7 @@ def _reindex_columns(self, columns, method, copy, level, fill_value=None, if level is not None: raise TypeError('Reindex by level not supported for sparse') - if notna(fill_value): + if not (isna(fill_value) or fill_value is _default_fill_value): raise NotImplementedError("'fill_value' argument is not supported") if limit: