Skip to content

Commit 67ba9dd

Browse files
committed
more with default fill value
1 parent eba137f commit 67ba9dd

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

pandas/core/dtypes/cast.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from pandas._libs import tslib, lib
99
from pandas._libs.tslib import iNaT
10-
from pandas.compat import string_types, text_type, PY3
10+
from pandas.compat import string_types, text_type, PY3, _default_fill_value
1111
from .common import (_ensure_object, is_bool, is_integer, is_float,
1212
is_complex, is_datetimetz, is_categorical_dtype,
1313
is_datetimelike,
@@ -255,6 +255,8 @@ def changeit():
255255

256256

257257
def maybe_promote(dtype, fill_value=np.nan):
258+
if fill_value is _default_fill_value:
259+
fill_value = np.nan
258260

259261
# if we passed an array here, determine the fill value by dtype
260262
if isinstance(fill_value, np.ndarray):

pandas/core/generic.py

+3
Original file line numberDiff line numberDiff line change
@@ -7263,6 +7263,9 @@ def _align_frame(self, other, join='outer', axis=None, level=None,
72637263
clidx, cridx = None, None
72647264

72657265
is_series = isinstance(self, ABCSeries)
7266+
if fill_value is _default_fill_value:
7267+
# XXX: per-column?
7268+
fill_value = np.nan
72667269

72677270
if axis is None or axis == 0:
72687271
if not self.index.equals(other.index):

pandas/core/internals.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -4417,9 +4417,15 @@ def reindex_indexer(self, new_axis, indexer, axis, fill_value=None,
44174417
else:
44184418
if fill_value is None:
44194419
fill_value = _default_fill_value
4420-
new_blocks = [blk.take_nd(indexer, axis=axis, fill_tuple=(
4421-
fill_value if fill_value is not _default_fill_value else blk.fill_value,))
4422-
for blk in self.blocks]
4420+
4421+
new_blocks = []
4422+
for blk in self.blocks:
4423+
if fill_value is not _default_fill_value:
4424+
fill_tuple = (fill_value,)
4425+
else:
4426+
fill_tuple = (blk.fill_value,)
4427+
new_blocks = [blk.take_nd(indexer, axis=axis, fill_tuple=fill_tuple)
4428+
for blk in self.blocks]
44234429

44244430
new_axes = list(self.axes)
44254431
new_axes[axis] = new_axis

pandas/core/series.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3217,7 +3217,7 @@ def _reindex_indexer(self, new_index, indexer, copy):
32173217
return self
32183218

32193219
from pandas.core.dtypes.missing import na_value_for_dtype
3220-
fill_value = na_value_for_dtype(self.dtype)
3220+
fill_value = na_value_for_dtype(self.dtype, compat=False)
32213221
new_values = algorithms.take(self._values, indexer,
32223222
fill_value=fill_value)
32233223
return self._constructor(new_values, index=new_index)

pandas/core/sparse/frame.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# pylint: disable=E1101,E1103,W0231,E0202
77

88
import warnings
9-
from pandas.compat import lmap
9+
from pandas.compat import lmap, _default_fill_value
1010
from pandas import compat
1111
import numpy as np
1212

@@ -690,7 +690,7 @@ def _reindex_columns(self, columns, method, copy, level, fill_value=None,
690690
if level is not None:
691691
raise TypeError('Reindex by level not supported for sparse')
692692

693-
if notna(fill_value):
693+
if not (isna(fill_value) or fill_value is _default_fill_value):
694694
raise NotImplementedError("'fill_value' argument is not supported")
695695

696696
if limit:

0 commit comments

Comments
 (0)