Skip to content

Remove unused fastpath kwarg from Blocks #19265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 19, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 44 additions & 55 deletions pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,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 @@ -210,19 +210,18 @@ def make_block(self, values, placement=None, ndim=None, **kwargs):

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

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, **kwargs):
""" 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)
**kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kwargs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last pass pulled out the kwargs for make_block method; this is for make_block_same_class. I'll do another pass and see how it goes.


@mgr_locs.setter
def mgr_locs(self, new_mgr_locs):
Expand Down Expand Up @@ -340,7 +339,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 @@ -459,7 +458,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 @@ -518,7 +517,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(values, klass=self.__class__)]
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(interp_values, klass=self.__class__)]
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 @@ -1954,12 +1952,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 @@ -2092,13 +2090,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 @@ -2345,12 +2342,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 @@ -2467,12 +2463,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 @@ -2603,13 +2599,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 @@ -2619,7 +2613,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 @@ -2825,7 +2819,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, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kwargs?

""" return a new block """
if dtype is None:
dtype = values.dtype
Expand All @@ -2844,8 +2838,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 @@ -2854,7 +2847,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 @@ -2921,6 +2914,7 @@ def sparse_reindex(self, new_index):
placement=self.mgr_locs)


# TODO: deprecate `fastpath` kwarg after getting pyarrow to stop passing it
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of the comment. post a JIRA to arrow (fix even better). pass this as fastpath=None and you can show a DeprecationWarning if fastpath is not None.

def make_block(values, placement, klass=None, ndim=None, dtype=None,
fastpath=False):
if klass is None:
Expand Down Expand Up @@ -2952,10 +2946,10 @@ def make_block(values, placement, klass=None, ndim=None, dtype=None,
klass = ObjectBlock

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 @@ -3015,7 +3009,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 @@ -3626,8 +3620,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 @@ -3782,7 +3775,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 @@ -3792,8 +3785,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 @@ -3896,7 +3888,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 @@ -4418,8 +4410,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 @@ -4734,8 +4725,7 @@ def form_blocks(arrays, names, axes):
if len(datetime_tz_items):
dttz_blocks = [make_block(array,
klass=DatetimeTZBlock,
fastpath=True,
placement=[i], )
placement=[i])
for i, _, array in datetime_tz_items]
blocks.extend(dttz_blocks)

Expand All @@ -4752,7 +4742,7 @@ def form_blocks(arrays, names, axes):
blocks.extend(sparse_blocks)

if len(cat_items) > 0:
cat_blocks = [make_block(array, klass=CategoricalBlock, fastpath=True,
cat_blocks = [make_block(array, klass=CategoricalBlock,
placement=[i])
for i, _, array in cat_items]
blocks.extend(cat_blocks)
Expand Down Expand Up @@ -4809,8 +4799,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 @@ -4894,7 +4883,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