Skip to content

Commit c721915

Browse files
committed
Removed default_fill_value
1 parent 37915e9 commit c721915

File tree

9 files changed

+20
-91
lines changed

9 files changed

+20
-91
lines changed

pandas/compat/__init__.py

-3
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,3 @@ def is_platform_mac():
451451

452452
def is_platform_32bit():
453453
return struct.calcsize("P") * 8 < 64
454-
455-
456-
_default_fill_value = object()

pandas/core/algorithms.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
_ensure_platform_int, _ensure_object,
3131
_ensure_float64, _ensure_uint64,
3232
_ensure_int64)
33-
from pandas.compat import _default_fill_value
3433
from pandas.compat.numpy import _np_version_under1p10
3534
from pandas.core.dtypes.missing import isna, na_value_for_dtype
3635

@@ -1449,10 +1448,10 @@ def func(arr, indexer, out, fill_value=np.nan):
14491448
return func
14501449

14511450

1452-
def take(arr, indexer, fill_value=_default_fill_value):
1451+
def take(arr, indexer, fill_value=None, allow_fill=None):
14531452
indexer = np.asarray(indexer)
14541453

1455-
if fill_value is _default_fill_value:
1454+
if allow_fill is None:
14561455
# NumPy style
14571456
result = arr.take(indexer)
14581457
else:

pandas/core/arrays/base.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import numpy as np
1111

1212
from pandas.errors import AbstractMethodError
13-
from pandas.compat import _default_fill_value
1413
from pandas.compat.numpy import function as nv
1514
from pandas.util._decorators import Appender, Substitution
1615

@@ -535,7 +534,7 @@ def _values_for_take(self):
535534

536535
@Substitution(arr='')
537536
@Appender(_take_docstring)
538-
def take(self, indexer, fill_value=_default_fill_value):
537+
def take(self, indexer, fill_value=None, allow_fill=None):
539538
# type: (Sequence[int], Optional[Any]) -> ExtensionArray
540539
# assert fill_value is not np.nan
541540
from pandas.core.algorithms import take

pandas/core/dtypes/cast.py

+1-4
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, _default_fill_value
10+
from pandas.compat import string_types, text_type, PY3
1111
from .common import (_ensure_object, is_bool, is_integer, is_float,
1212
is_complex, is_datetimetz, is_categorical_dtype,
1313
is_datetimelike,
@@ -255,9 +255,6 @@ 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
260-
261258
# if we passed an array here, determine the fill value by dtype
262259
if isinstance(fill_value, np.ndarray):
263260
if issubclass(fill_value.dtype.type, (np.datetime64, np.timedelta64)):

pandas/core/frame.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
from pandas.core.arrays import Categorical, ExtensionArray
7878
import pandas.core.algorithms as algorithms
7979
from pandas.compat import (range, map, zip, lrange, lmap, lzip, StringIO, u,
80-
OrderedDict, raise_with_traceback, _default_fill_value)
80+
OrderedDict, raise_with_traceback)
8181
from pandas import compat
8282
from pandas.compat import PY36
8383
from pandas.compat.numpy import function as nv
@@ -3504,7 +3504,7 @@ def _reindex_multi(self, axes, copy, fill_value):
35043504

35053505
@Appender(_shared_docs['align'] % _shared_doc_kwargs)
35063506
def align(self, other, join='outer', axis=None, level=None, copy=True,
3507-
fill_value=_default_fill_value, method=None, limit=None, fill_axis=0,
3507+
fill_value=None, method=None, limit=None, fill_axis=0,
35083508
broadcast_axis=None):
35093509
return super(DataFrame, self).align(other, join=join, axis=axis,
35103510
level=level, copy=copy,

pandas/core/generic.py

+4-13
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@
5050
from pandas import compat
5151
from pandas.compat.numpy import function as nv
5252
from pandas.compat import (map, zip, lzip, lrange, string_types, to_str,
53-
isidentifier, set_function_name, cPickle as pkl,
54-
_default_fill_value)
53+
isidentifier, set_function_name, cPickle as pkl)
5554
from pandas.core.ops import _align_method_FRAME
5655
import pandas.core.nanops as nanops
5756
from pandas.util._decorators import (Appender, Substitution,
@@ -3661,7 +3660,7 @@ def reindex(self, *args, **kwargs):
36613660
copy = kwargs.pop('copy', True)
36623661
limit = kwargs.pop('limit', None)
36633662
tolerance = kwargs.pop('tolerance', None)
3664-
fill_value = kwargs.pop('fill_value', _default_fill_value)
3663+
fill_value = kwargs.pop('fill_value', np.nan)
36653664

36663665
# Series.reindex doesn't use / need the axis kwarg
36673666
# We pop and ignore it here, to make writing Series/Frame generic code
@@ -3791,9 +3790,7 @@ def reindex_axis(self, labels, axis=0, method=None, level=None, copy=True,
37913790
return self._reindex_with_indexers({axis: [new_index, indexer]},
37923791
fill_value=fill_value, copy=copy)
37933792

3794-
def _reindex_with_indexers(self, reindexers,
3795-
fill_value=_default_fill_value,
3796-
copy=False,
3793+
def _reindex_with_indexers(self, reindexers, fill_value=np.nan, copy=False,
37973794
allow_dups=False):
37983795
"""allow_dups indicates an internal call here """
37993796

@@ -7212,7 +7209,7 @@ def ranker(data):
72127209

72137210
@Appender(_shared_docs['align'] % _shared_doc_kwargs)
72147211
def align(self, other, join='outer', axis=None, level=None, copy=True,
7215-
fill_value=_default_fill_value, method=None, limit=None, fill_axis=0,
7212+
fill_value=None, method=None, limit=None, fill_axis=0,
72167213
broadcast_axis=None):
72177214
from pandas import DataFrame, Series
72187215
method = missing.clean_fill_method(method)
@@ -7263,9 +7260,6 @@ def _align_frame(self, other, join='outer', axis=None, level=None,
72637260
clidx, cridx = None, None
72647261

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

72707264
if axis is None or axis == 0:
72717265
if not self.index.equals(other.index):
@@ -7365,9 +7359,6 @@ def _align_series(self, other, join='outer', axis=None, level=None,
73657359
right = other.reindex(join_index, level=level)
73667360

73677361
# fill
7368-
if fill_value is _default_fill_value:
7369-
fill_value = None
7370-
73717362
fill_na = notna(fill_value) or (method is not None)
73727363
if fill_na:
73737364
left = left.fillna(fill_value, method=method, limit=limit,

pandas/core/internals.py

+5-56
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import warnings
2-
32
import copy
43
from warnings import catch_warnings
54
import inspect
@@ -83,7 +82,7 @@
8382
from pandas.util._decorators import cache_readonly
8483
from pandas.util._validators import validate_bool_kwarg
8584
from pandas import compat
86-
from pandas.compat import range, map, zip, u, _default_fill_value
85+
from pandas.compat import range, map, zip, u
8786

8887

8988
class Block(PandasObject):
@@ -1889,10 +1888,6 @@ def _holder(self):
18891888
# For extension blocks, the holder is values-dependent.
18901889
return type(self.values)
18911890

1892-
@property
1893-
def fill_value(self):
1894-
return self.values.dtype.na_value # TODO: change to _na_value
1895-
18961891
@property
18971892
def _can_hold_na(self):
18981893
# The default ExtensionArray._can_hold_na is True
@@ -4391,8 +4386,6 @@ def reindex_indexer(self, new_axis, indexer, axis, fill_value=None,
43914386
43924387
pandas-indexer with -1's only.
43934388
"""
4394-
# TODO: see if we can make fill_value be {col -> fill_value}
4395-
# maybe earlier...
43964389
if indexer is None:
43974390
if new_axis is self.axes[axis] and not copy:
43984391
return self
@@ -4415,17 +4408,9 @@ def reindex_indexer(self, new_axis, indexer, axis, fill_value=None,
44154408
new_blocks = self._slice_take_blocks_ax0(indexer,
44164409
fill_tuple=(fill_value,))
44174410
else:
4418-
if fill_value is None:
4419-
fill_value = _default_fill_value
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]
4411+
new_blocks = [blk.take_nd(indexer, axis=axis, fill_tuple=(
4412+
fill_value if fill_value is not None else blk.fill_value,))
4413+
for blk in self.blocks]
44294414

44304415
new_axes = list(self.axes)
44314416
new_axes[axis] = new_axis
@@ -4451,9 +4436,6 @@ def _slice_take_blocks_ax0(self, slice_or_indexer, fill_tuple=None):
44514436
if self._is_single_block:
44524437
blk = self.blocks[0]
44534438

4454-
if allow_fill and fill_tuple[0] is _default_fill_value:
4455-
fill_tuple = (blk.fill_value,)
4456-
44574439
if sl_type in ('slice', 'mask'):
44584440
return [blk.getitem_block(slobj, new_mgr_locs=slice(0, sllen))]
44594441
elif not allow_fill or self.ndim == 1:
@@ -5422,25 +5404,6 @@ def concatenate_block_managers(mgrs_indexers, axes, concat_axis, copy):
54225404
elif is_uniform_join_units(join_units):
54235405
b = join_units[0].block.concat_same_type(
54245406
[ju.block for ju in join_units], placement=placement)
5425-
elif is_uniform_reindexer(join_units):
5426-
old_block = join_units[0].block
5427-
5428-
new_values = concatenate_join_units(join_units, concat_axis,
5429-
copy=copy)
5430-
if new_values.ndim == 2:
5431-
# XXX: categorical returns a categorical here
5432-
# EA returns a 2d ndarray
5433-
# need to harmoinze these to always be EAs?
5434-
assert new_values.shape[0] == 1
5435-
new_values = new_values[0]
5436-
5437-
assert isinstance(old_block._holder, ABCExtensionArray)
5438-
5439-
b = old_block.make_block_same_class(
5440-
old_block._holder._from_sequence(new_values),
5441-
placement=placement
5442-
)
5443-
54445407
else:
54455408
b = make_block(
54465409
concatenate_join_units(join_units, concat_axis, copy=copy),
@@ -5471,13 +5434,6 @@ def is_uniform_join_units(join_units):
54715434
len(join_units) > 1)
54725435

54735436

5474-
def is_uniform_reindexer(join_units):
5475-
# For when we know we can reindex without changing type
5476-
return (
5477-
all(ju.block and ju.block.is_extension for ju in join_units)
5478-
)
5479-
5480-
54815437
def get_empty_dtype_and_na(join_units):
54825438
"""
54835439
Return dtype and N/A values to use when concatenating specified units.
@@ -5505,15 +5461,12 @@ def get_empty_dtype_and_na(join_units):
55055461

55065462
upcast_classes = defaultdict(list)
55075463
null_upcast_classes = defaultdict(list)
5508-
55095464
for dtype, unit in zip(dtypes, join_units):
55105465
if dtype is None:
55115466
continue
55125467

55135468
if is_categorical_dtype(dtype):
55145469
upcast_cls = 'category'
5515-
elif is_extension_array_dtype(dtype):
5516-
upcast_cls = 'extension'
55175470
elif is_datetimetz(dtype):
55185471
upcast_cls = 'datetimetz'
55195472
elif issubclass(dtype.type, np.bool_):
@@ -5543,8 +5496,6 @@ def get_empty_dtype_and_na(join_units):
55435496
# create the result
55445497
if 'object' in upcast_classes:
55455498
return np.dtype(np.object_), np.nan
5546-
elif 'extension' in upcast_classes:
5547-
return np.dtype(np.object_), None
55485499
elif 'bool' in upcast_classes:
55495500
if has_none_blocks:
55505501
return np.dtype(np.object_), np.nan
@@ -5804,9 +5755,7 @@ def dtype(self):
58045755
if self.block is None:
58055756
raise AssertionError("Block is None, no dtype")
58065757

5807-
if not self.needs_filling or self.block.is_extension:
5808-
# ExtensionDtypes by definition can hold their
5809-
# NA value.
5758+
if not self.needs_filling:
58105759
return self.block.dtype
58115760
else:
58125761
return _get_dtype(maybe_promote(self.block.dtype,

pandas/core/series.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
from pandas import compat
5757
from pandas.io.formats.terminal import get_terminal_size
5858
from pandas.compat import (
59-
zip, u, OrderedDict, StringIO, range, get_range_parameters, PY36, _default_fill_value)
59+
zip, u, OrderedDict, StringIO, range, get_range_parameters, PY36)
6060
from pandas.compat.numpy import function as nv
6161

6262
import pandas.core.ops as ops
@@ -3216,10 +3216,7 @@ def _reindex_indexer(self, new_index, indexer, copy):
32163216
return self.copy()
32173217
return self
32183218

3219-
from pandas.core.dtypes.missing import na_value_for_dtype
3220-
fill_value = na_value_for_dtype(self.dtype, compat=False)
3221-
new_values = algorithms.take(self._values, indexer,
3222-
fill_value=fill_value)
3219+
new_values = algorithms.take_1d(self._values, indexer)
32233220
return self._constructor(new_values, index=new_index)
32243221

32253222
def _needs_reindex_multi(self, axes, method, level):
@@ -3230,7 +3227,7 @@ def _needs_reindex_multi(self, axes, method, level):
32303227

32313228
@Appender(generic._shared_docs['align'] % _shared_doc_kwargs)
32323229
def align(self, other, join='outer', axis=None, level=None, copy=True,
3233-
fill_value=_default_fill_value, method=None, limit=None, fill_axis=0,
3230+
fill_value=None, method=None, limit=None, fill_axis=0,
32343231
broadcast_axis=None):
32353232
return super(Series, self).align(other, join=join, axis=axis,
32363233
level=level, copy=copy,

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, _default_fill_value
9+
from pandas.compat import lmap
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 not (isna(fill_value) or fill_value is _default_fill_value):
693+
if notna(fill_value):
694694
raise NotImplementedError("'fill_value' argument is not supported")
695695

696696
if limit:

0 commit comments

Comments
 (0)