-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4ca06ee
remove unused fastpath kwarg from Blocks
jbrockmendel 5a0e5f2
restore fastpath to internals.make_block for downstream compat
jbrockmendel 028ce18
remove more unused kwargs, DeprecationWarning for make_block fastpath
jbrockmendel 75a0a77
test that deprecationwarning is emitted
jbrockmendel d2072c6
Merge branch 'master' of https://github.com/pandas-dev/pandas into no…
jbrockmendel 3148e52
whitespace cleanup
jbrockmendel 1ee7940
remove unneeded comment
jbrockmendel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
|
@@ -198,7 +198,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 | ||
|
@@ -208,21 +208,21 @@ 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) | ||
# TODO: Why not set default for ndim like we do for self.make_block? | ||
return make_block(values, placement=placement, ndim=ndim, | ||
klass=self.__class__) | ||
|
||
@mgr_locs.setter | ||
def mgr_locs(self, new_mgr_locs): | ||
|
@@ -340,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] | ||
|
@@ -459,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 | ||
|
@@ -518,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: | ||
|
@@ -910,7 +910,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, | ||
|
@@ -1026,7 +1026,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): | ||
""" | ||
|
@@ -1161,7 +1161,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, | ||
|
@@ -1201,8 +1201,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): | ||
|
@@ -1246,7 +1245,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 """ | ||
|
@@ -1276,7 +1275,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): | ||
""" | ||
|
@@ -1416,7 +1415,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): | ||
|
@@ -1696,7 +1695,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 | ||
|
@@ -1954,12 +1953,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): | ||
|
@@ -2092,13 +2091,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): | ||
|
@@ -2345,12 +2343,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): | ||
|
@@ -2467,12 +2464,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): | ||
""" | ||
|
@@ -2603,13 +2600,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) | ||
|
@@ -2619,7 +2614,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 """ | ||
|
@@ -2825,7 +2820,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 | ||
|
@@ -2844,8 +2839,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: | ||
|
@@ -2854,7 +2848,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, | ||
|
@@ -2922,7 +2916,11 @@ def sparse_reindex(self, new_index): | |
|
||
|
||
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 " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this needs a test |
||
"in a future release.", DeprecationWarning) | ||
if klass is None: | ||
dtype = dtype or values.dtype | ||
vtype = dtype.type | ||
|
@@ -2952,10 +2950,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 | ||
|
||
|
@@ -3015,7 +3013,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) | ||
|
||
|
@@ -3626,8 +3624,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 | ||
|
||
|
@@ -3782,7 +3779,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: | ||
|
@@ -3792,8 +3789,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) | ||
|
||
|
@@ -3896,7 +3892,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): | ||
|
@@ -4418,8 +4414,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] | ||
|
||
|
@@ -4734,8 +4729,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) | ||
|
||
|
@@ -4752,7 +4746,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) | ||
|
@@ -4809,8 +4803,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 | ||
|
@@ -4894,7 +4887,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 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should introduce such todo questions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will remove. Any thoughts on the answer?