Skip to content

Commit

Permalink
Remove unused fastpath kwarg from Blocks (#19265)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and jreback committed Jan 19, 2018
1 parent f0cd23c commit 1245f06
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 59 deletions.
109 changes: 50 additions & 59 deletions pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Block(PandasObject):
_holder = None
_concatenator = staticmethod(np.concatenate)

def __init__(self, values, placement, ndim=None, fastpath=False):
def __init__(self, values, placement, ndim=None):
if ndim is None:
ndim = values.ndim
elif values.ndim != ndim:
Expand Down Expand Up @@ -206,7 +206,7 @@ def array_dtype(self):
"""
return self.dtype

def make_block(self, values, placement=None, ndim=None, **kwargs):
def make_block(self, values, placement=None, ndim=None):
"""
Create a new block, with type inference propagate any values that are
not specified
Expand All @@ -216,21 +216,20 @@ def make_block(self, values, placement=None, ndim=None, **kwargs):
if ndim is None:
ndim = self.ndim

return make_block(values, placement=placement, ndim=ndim, **kwargs)
return make_block(values, placement=placement, ndim=ndim)

def make_block_scalar(self, values, **kwargs):
def make_block_scalar(self, values):
"""
Create a ScalarBlock
"""
return ScalarBlock(values)

def make_block_same_class(self, values, placement=None, fastpath=True,
**kwargs):
def make_block_same_class(self, values, placement=None, ndim=None):
""" Wrap given values in a block of same type as self. """
if placement is None:
placement = self.mgr_locs
return make_block(values, placement=placement, klass=self.__class__,
fastpath=fastpath, **kwargs)
return make_block(values, placement=placement, ndim=ndim,
klass=self.__class__)

def __unicode__(self):

Expand Down Expand Up @@ -341,7 +340,7 @@ def reindex_axis(self, indexer, method=None, axis=1, fill_value=None,

new_values = algos.take_nd(self.values, indexer, axis,
fill_value=fill_value, mask_info=mask_info)
return self.make_block(new_values, fastpath=True)
return self.make_block(new_values)

def iget(self, i):
return self.values[i]
Expand Down Expand Up @@ -460,7 +459,7 @@ def make_a_block(nv, ref_loc):
except (AttributeError, NotImplementedError):
pass
block = self.make_block(values=nv,
placement=ref_loc, fastpath=True)
placement=ref_loc)
return block

# ndim == 1
Expand Down Expand Up @@ -519,7 +518,7 @@ def downcast(self, dtypes=None, mgr=None):
dtypes = 'infer'

nv = maybe_downcast_to_dtype(values, dtypes)
return self.make_block(nv, fastpath=True)
return self.make_block(nv)

# ndim > 1
if dtypes is None:
Expand Down Expand Up @@ -910,7 +909,7 @@ def _is_empty_indexer(indexer):

# coerce and try to infer the dtypes of the result
values = self._try_coerce_and_cast_result(values, dtype)
block = self.make_block(transf(values), fastpath=True)
block = self.make_block(transf(values))
return block

def putmask(self, mask, new, align=True, inplace=False, axis=0,
Expand Down Expand Up @@ -1026,7 +1025,7 @@ def f(m, v, i):
if transpose:
new_values = new_values.T

return [self.make_block(new_values, fastpath=True)]
return [self.make_block(new_values)]

def coerce_to_target_dtype(self, other):
"""
Expand Down Expand Up @@ -1161,7 +1160,7 @@ def _interpolate_with_fill(self, method='pad', axis=0, inplace=False,
dtype=self.dtype)
values = self._try_coerce_result(values)

blocks = [self.make_block(values, klass=self.__class__, fastpath=True)]
blocks = [self.make_block_same_class(values, ndim=self.ndim)]
return self._maybe_downcast(blocks, downcast)

def _interpolate(self, method=None, index=None, values=None,
Expand Down Expand Up @@ -1201,8 +1200,7 @@ def func(x):
# interp each column independently
interp_values = np.apply_along_axis(func, axis, data)

blocks = [self.make_block(interp_values, klass=self.__class__,
fastpath=True)]
blocks = [self.make_block_same_class(interp_values)]
return self._maybe_downcast(blocks, downcast)

def take_nd(self, indexer, axis, new_mgr_locs=None, fill_tuple=None):
Expand Down Expand Up @@ -1246,7 +1244,7 @@ def take_nd(self, indexer, axis, new_mgr_locs=None, fill_tuple=None):
def diff(self, n, axis=1, mgr=None):
""" return block for the diff of the values """
new_values = algos.diff(self.values, n, axis=axis)
return [self.make_block(values=new_values, fastpath=True)]
return [self.make_block(values=new_values)]

def shift(self, periods, axis=0, mgr=None):
""" shift the block by periods, possibly upcast """
Expand Down Expand Up @@ -1276,7 +1274,7 @@ def shift(self, periods, axis=0, mgr=None):
if f_ordered:
new_values = new_values.T

return [self.make_block(new_values, fastpath=True)]
return [self.make_block(new_values)]

def eval(self, func, other, errors='raise', try_cast=False, mgr=None):
"""
Expand Down Expand Up @@ -1416,7 +1414,7 @@ def handle_error():
result = self._try_cast_result(result)

result = _block_shape(result, ndim=self.ndim)
return [self.make_block(result, fastpath=True, )]
return [self.make_block(result)]

def where(self, other, cond, align=True, errors='raise',
try_cast=False, axis=0, transpose=False, mgr=None):
Expand Down Expand Up @@ -1696,7 +1694,7 @@ class NonConsolidatableMixIn(object):
_validate_ndim = False
_holder = None

def __init__(self, values, placement, ndim=None, fastpath=False, **kwargs):
def __init__(self, values, placement, ndim=None):

# Placement must be converted to BlockPlacement via property setter
# before ndim logic, because placement may be a slice which doesn't
Expand Down Expand Up @@ -1953,12 +1951,12 @@ class TimeDeltaBlock(DatetimeLikeBlockMixin, IntBlock):
_can_hold_na = True
is_numeric = False

def __init__(self, values, placement, fastpath=False, **kwargs):
def __init__(self, values, placement, ndim=None):
if values.dtype != _TD_DTYPE:
values = conversion.ensure_timedelta64ns(values)

super(TimeDeltaBlock, self).__init__(values, fastpath=True,
placement=placement, **kwargs)
super(TimeDeltaBlock, self).__init__(values,
placement=placement, ndim=ndim)

@property
def _box_func(self):
Expand Down Expand Up @@ -2091,13 +2089,12 @@ class ObjectBlock(Block):
is_object = True
_can_hold_na = True

def __init__(self, values, ndim=2, fastpath=False, placement=None,
**kwargs):
def __init__(self, values, placement=None, ndim=2):
if issubclass(values.dtype.type, compat.string_types):
values = np.array(values, dtype=object)

super(ObjectBlock, self).__init__(values, ndim=ndim, fastpath=fastpath,
placement=placement, **kwargs)
super(ObjectBlock, self).__init__(values, ndim=ndim,
placement=placement)

@property
def is_bool(self):
Expand Down Expand Up @@ -2344,12 +2341,11 @@ class CategoricalBlock(NonConsolidatableMixIn, ObjectBlock):
_holder = Categorical
_concatenator = staticmethod(_concat._concat_categorical)

def __init__(self, values, placement, fastpath=False, **kwargs):
def __init__(self, values, placement, ndim=None):

# coerce to categorical if we can
super(CategoricalBlock, self).__init__(_maybe_to_categorical(values),
fastpath=True,
placement=placement, **kwargs)
placement=placement, ndim=ndim)

@property
def is_view(self):
Expand Down Expand Up @@ -2466,12 +2462,12 @@ class DatetimeBlock(DatetimeLikeBlockMixin, Block):
is_datetime = True
_can_hold_na = True

def __init__(self, values, placement, fastpath=False, **kwargs):
def __init__(self, values, placement, ndim=None):
if values.dtype != _NS_DTYPE:
values = conversion.ensure_datetime64ns(values)

super(DatetimeBlock, self).__init__(values, fastpath=True,
placement=placement, **kwargs)
super(DatetimeBlock, self).__init__(values,
placement=placement, ndim=ndim)

def _astype(self, dtype, mgr=None, **kwargs):
"""
Expand Down Expand Up @@ -2602,13 +2598,11 @@ class DatetimeTZBlock(NonConsolidatableMixIn, DatetimeBlock):
_concatenator = staticmethod(_concat._concat_datetime)
is_datetimetz = True

def __init__(self, values, placement, ndim=2, **kwargs):
def __init__(self, values, placement, ndim=2, dtype=None):

if not isinstance(values, self._holder):
values = self._holder(values)

dtype = kwargs.pop('dtype', None)

if dtype is not None:
if isinstance(dtype, compat.string_types):
dtype = DatetimeTZDtype.construct_from_string(dtype)
Expand All @@ -2618,7 +2612,7 @@ def __init__(self, values, placement, ndim=2, **kwargs):
raise ValueError("cannot create a DatetimeTZBlock without a tz")

super(DatetimeTZBlock, self).__init__(values, placement=placement,
ndim=ndim, **kwargs)
ndim=ndim)

def copy(self, deep=True, mgr=None):
""" copy constructor """
Expand Down Expand Up @@ -2824,7 +2818,7 @@ def copy(self, deep=True, mgr=None):

def make_block_same_class(self, values, placement, sparse_index=None,
kind=None, dtype=None, fill_value=None,
copy=False, fastpath=True, **kwargs):
copy=False, ndim=None):
""" return a new block """
if dtype is None:
dtype = values.dtype
Expand All @@ -2843,8 +2837,7 @@ def make_block_same_class(self, values, placement, sparse_index=None,
# won't take space since there's 0 items, plus it will preserve
# the dtype.
return self.make_block(np.empty(values.shape, dtype=dtype),
placement,
fastpath=True)
placement)
elif nitems > 1:
raise ValueError("Only 1-item 2d sparse blocks are supported")
else:
Expand All @@ -2853,7 +2846,7 @@ def make_block_same_class(self, values, placement, sparse_index=None,
new_values = SparseArray(values, sparse_index=sparse_index,
kind=kind or self.kind, dtype=dtype,
fill_value=fill_value, copy=copy)
return self.make_block(new_values, fastpath=fastpath,
return self.make_block(new_values,
placement=placement)

def interpolate(self, method='pad', axis=0, inplace=False, limit=None,
Expand Down Expand Up @@ -2962,16 +2955,20 @@ def get_block_type(values, dtype=None):


def make_block(values, placement, klass=None, ndim=None, dtype=None,
fastpath=False):
fastpath=None):
if fastpath is not None:
# GH#19265 pyarrow is passing this
warnings.warn("fastpath argument is deprecated, will be removed "
"in a future release.", DeprecationWarning)
if klass is None:
dtype = dtype or values.dtype
klass = get_block_type(values, dtype)

elif klass is DatetimeTZBlock and not is_datetimetz(values):
return klass(values, ndim=ndim, fastpath=fastpath,
return klass(values, ndim=ndim,
placement=placement, dtype=dtype)

return klass(values, ndim=ndim, fastpath=fastpath, placement=placement)
return klass(values, ndim=ndim, placement=placement)

# TODO: flexible with index=None and/or items=None

Expand Down Expand Up @@ -3031,7 +3028,7 @@ class BlockManager(PandasObject):
__slots__ = ['axes', 'blocks', '_ndim', '_shape', '_known_consolidated',
'_is_consolidated', '_blknos', '_blklocs']

def __init__(self, blocks, axes, do_integrity_check=True, fastpath=True):
def __init__(self, blocks, axes, do_integrity_check=True):
self.axes = [_ensure_index(ax) for ax in axes]
self.blocks = tuple(blocks)

Expand Down Expand Up @@ -3642,8 +3639,7 @@ def get_slice(self, slobj, axis=0):
new_axes = list(self.axes)
new_axes[axis] = new_axes[axis][slobj]

bm = self.__class__(new_blocks, new_axes, do_integrity_check=False,
fastpath=True)
bm = self.__class__(new_blocks, new_axes, do_integrity_check=False)
bm._consolidate_inplace()
return bm

Expand Down Expand Up @@ -3798,7 +3794,7 @@ def xs(self, key, axis=1, copy=True, takeable=False):
# we must copy here as we are mixed type
for blk in self.blocks:
newb = make_block(values=blk.values[slicer],
klass=blk.__class__, fastpath=True,
klass=blk.__class__,
placement=blk.mgr_locs)
new_blocks.append(newb)
elif len(self.blocks) == 1:
Expand All @@ -3808,8 +3804,7 @@ def xs(self, key, axis=1, copy=True, takeable=False):
vals = vals.copy()
new_blocks = [make_block(values=vals,
placement=block.mgr_locs,
klass=block.__class__,
fastpath=True, )]
klass=block.__class__)]

return self.__class__(new_blocks, new_axes)

Expand Down Expand Up @@ -3912,7 +3907,7 @@ def iget(self, i, fastpath=True):
return SingleBlockManager(
[block.make_block_same_class(values,
placement=slice(0, len(values)),
ndim=1, fastpath=True)],
ndim=1)],
self.axes[1])

def get_scalar(self, tup):
Expand Down Expand Up @@ -4434,8 +4429,7 @@ def __init__(self, block, axis, do_integrity_check=False, fastpath=False):
block = block[0]

if not isinstance(block, Block):
block = make_block(block, placement=slice(0, len(axis)), ndim=1,
fastpath=True)
block = make_block(block, placement=slice(0, len(axis)), ndim=1)

self.blocks = [block]

Expand Down Expand Up @@ -4727,7 +4721,6 @@ def form_blocks(arrays, names, axes):
if len(items_dict['DatetimeTZBlock']):
dttz_blocks = [make_block(array,
klass=DatetimeTZBlock,
fastpath=True,
placement=[i])
for i, _, array in items_dict['DatetimeTZBlock']]
blocks.extend(dttz_blocks)
Expand All @@ -4745,8 +4738,7 @@ def form_blocks(arrays, names, axes):
blocks.extend(sparse_blocks)

if len(items_dict['CategoricalBlock']) > 0:
cat_blocks = [make_block(array, klass=CategoricalBlock, fastpath=True,
placement=[i])
cat_blocks = [make_block(array, klass=CategoricalBlock, placement=[i])
for i, _, array in items_dict['CategoricalBlock']]
blocks.extend(cat_blocks)

Expand Down Expand Up @@ -4802,8 +4794,7 @@ def _sparse_blockify(tuples, dtype=None):
new_blocks = []
for i, names, array in tuples:
array = _maybe_to_sparse(array)
block = make_block(array, klass=SparseBlock, fastpath=True,
placement=[i])
block = make_block(array, klass=SparseBlock, placement=[i])
new_blocks.append(block)

return new_blocks
Expand Down Expand Up @@ -4887,7 +4878,7 @@ def _merge_blocks(blocks, dtype=None, _can_consolidate=True):
new_values = new_values[argsort]
new_mgr_locs = new_mgr_locs[argsort]

return make_block(new_values, fastpath=True, placement=new_mgr_locs)
return make_block(new_values, placement=new_mgr_locs)

# no merge
return blocks
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/internals/test_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,3 +1253,11 @@ def test_binop_other(self, op, value, dtype):
result = op(s, e).dtypes
expected = op(s, value).dtypes
assert_series_equal(result, expected)


def test_deprecated_fastpath():
# GH#19265
values = np.random.rand(3, 3)
with tm.assert_produces_warning(DeprecationWarning,
check_stacklevel=False):
make_block(values, placement=np.arange(3), fastpath=True)

0 comments on commit 1245f06

Please sign in to comment.