Skip to content

Commit

Permalink
more with default fill value
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAugspurger committed Apr 25, 2018
1 parent eba137f commit 67ba9dd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
4 changes: 3 additions & 1 deletion pandas/core/dtypes/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 9 additions & 3 deletions pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/sparse/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 67ba9dd

Please sign in to comment.