Skip to content

Commit 1245f06

Browse files
jbrockmendeljreback
authored andcommitted
Remove unused fastpath kwarg from Blocks (#19265)
1 parent f0cd23c commit 1245f06

File tree

2 files changed

+58
-59
lines changed

2 files changed

+58
-59
lines changed

pandas/core/internals.py

+50-59
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class Block(PandasObject):
106106
_holder = None
107107
_concatenator = staticmethod(np.concatenate)
108108

109-
def __init__(self, values, placement, ndim=None, fastpath=False):
109+
def __init__(self, values, placement, ndim=None):
110110
if ndim is None:
111111
ndim = values.ndim
112112
elif values.ndim != ndim:
@@ -206,7 +206,7 @@ def array_dtype(self):
206206
"""
207207
return self.dtype
208208

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

219-
return make_block(values, placement=placement, ndim=ndim, **kwargs)
219+
return make_block(values, placement=placement, ndim=ndim)
220220

221-
def make_block_scalar(self, values, **kwargs):
221+
def make_block_scalar(self, values):
222222
"""
223223
Create a ScalarBlock
224224
"""
225225
return ScalarBlock(values)
226226

227-
def make_block_same_class(self, values, placement=None, fastpath=True,
228-
**kwargs):
227+
def make_block_same_class(self, values, placement=None, ndim=None):
229228
""" Wrap given values in a block of same type as self. """
230229
if placement is None:
231230
placement = self.mgr_locs
232-
return make_block(values, placement=placement, klass=self.__class__,
233-
fastpath=fastpath, **kwargs)
231+
return make_block(values, placement=placement, ndim=ndim,
232+
klass=self.__class__)
234233

235234
def __unicode__(self):
236235

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

342341
new_values = algos.take_nd(self.values, indexer, axis,
343342
fill_value=fill_value, mask_info=mask_info)
344-
return self.make_block(new_values, fastpath=True)
343+
return self.make_block(new_values)
345344

346345
def iget(self, i):
347346
return self.values[i]
@@ -460,7 +459,7 @@ def make_a_block(nv, ref_loc):
460459
except (AttributeError, NotImplementedError):
461460
pass
462461
block = self.make_block(values=nv,
463-
placement=ref_loc, fastpath=True)
462+
placement=ref_loc)
464463
return block
465464

466465
# ndim == 1
@@ -519,7 +518,7 @@ def downcast(self, dtypes=None, mgr=None):
519518
dtypes = 'infer'
520519

521520
nv = maybe_downcast_to_dtype(values, dtypes)
522-
return self.make_block(nv, fastpath=True)
521+
return self.make_block(nv)
523522

524523
# ndim > 1
525524
if dtypes is None:
@@ -910,7 +909,7 @@ def _is_empty_indexer(indexer):
910909

911910
# coerce and try to infer the dtypes of the result
912911
values = self._try_coerce_and_cast_result(values, dtype)
913-
block = self.make_block(transf(values), fastpath=True)
912+
block = self.make_block(transf(values))
914913
return block
915914

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

1029-
return [self.make_block(new_values, fastpath=True)]
1028+
return [self.make_block(new_values)]
10301029

10311030
def coerce_to_target_dtype(self, other):
10321031
"""
@@ -1161,7 +1160,7 @@ def _interpolate_with_fill(self, method='pad', axis=0, inplace=False,
11611160
dtype=self.dtype)
11621161
values = self._try_coerce_result(values)
11631162

1164-
blocks = [self.make_block(values, klass=self.__class__, fastpath=True)]
1163+
blocks = [self.make_block_same_class(values, ndim=self.ndim)]
11651164
return self._maybe_downcast(blocks, downcast)
11661165

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

1204-
blocks = [self.make_block(interp_values, klass=self.__class__,
1205-
fastpath=True)]
1203+
blocks = [self.make_block_same_class(interp_values)]
12061204
return self._maybe_downcast(blocks, downcast)
12071205

12081206
def take_nd(self, indexer, axis, new_mgr_locs=None, fill_tuple=None):
@@ -1246,7 +1244,7 @@ def take_nd(self, indexer, axis, new_mgr_locs=None, fill_tuple=None):
12461244
def diff(self, n, axis=1, mgr=None):
12471245
""" return block for the diff of the values """
12481246
new_values = algos.diff(self.values, n, axis=axis)
1249-
return [self.make_block(values=new_values, fastpath=True)]
1247+
return [self.make_block(values=new_values)]
12501248

12511249
def shift(self, periods, axis=0, mgr=None):
12521250
""" shift the block by periods, possibly upcast """
@@ -1276,7 +1274,7 @@ def shift(self, periods, axis=0, mgr=None):
12761274
if f_ordered:
12771275
new_values = new_values.T
12781276

1279-
return [self.make_block(new_values, fastpath=True)]
1277+
return [self.make_block(new_values)]
12801278

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

14181416
result = _block_shape(result, ndim=self.ndim)
1419-
return [self.make_block(result, fastpath=True, )]
1417+
return [self.make_block(result)]
14201418

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

1699-
def __init__(self, values, placement, ndim=None, fastpath=False, **kwargs):
1697+
def __init__(self, values, placement, ndim=None):
17001698

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

1956-
def __init__(self, values, placement, fastpath=False, **kwargs):
1954+
def __init__(self, values, placement, ndim=None):
19571955
if values.dtype != _TD_DTYPE:
19581956
values = conversion.ensure_timedelta64ns(values)
19591957

1960-
super(TimeDeltaBlock, self).__init__(values, fastpath=True,
1961-
placement=placement, **kwargs)
1958+
super(TimeDeltaBlock, self).__init__(values,
1959+
placement=placement, ndim=ndim)
19621960

19631961
@property
19641962
def _box_func(self):
@@ -2091,13 +2089,12 @@ class ObjectBlock(Block):
20912089
is_object = True
20922090
_can_hold_na = True
20932091

2094-
def __init__(self, values, ndim=2, fastpath=False, placement=None,
2095-
**kwargs):
2092+
def __init__(self, values, placement=None, ndim=2):
20962093
if issubclass(values.dtype.type, compat.string_types):
20972094
values = np.array(values, dtype=object)
20982095

2099-
super(ObjectBlock, self).__init__(values, ndim=ndim, fastpath=fastpath,
2100-
placement=placement, **kwargs)
2096+
super(ObjectBlock, self).__init__(values, ndim=ndim,
2097+
placement=placement)
21012098

21022099
@property
21032100
def is_bool(self):
@@ -2344,12 +2341,11 @@ class CategoricalBlock(NonConsolidatableMixIn, ObjectBlock):
23442341
_holder = Categorical
23452342
_concatenator = staticmethod(_concat._concat_categorical)
23462343

2347-
def __init__(self, values, placement, fastpath=False, **kwargs):
2344+
def __init__(self, values, placement, ndim=None):
23482345

23492346
# coerce to categorical if we can
23502347
super(CategoricalBlock, self).__init__(_maybe_to_categorical(values),
2351-
fastpath=True,
2352-
placement=placement, **kwargs)
2348+
placement=placement, ndim=ndim)
23532349

23542350
@property
23552351
def is_view(self):
@@ -2466,12 +2462,12 @@ class DatetimeBlock(DatetimeLikeBlockMixin, Block):
24662462
is_datetime = True
24672463
_can_hold_na = True
24682464

2469-
def __init__(self, values, placement, fastpath=False, **kwargs):
2465+
def __init__(self, values, placement, ndim=None):
24702466
if values.dtype != _NS_DTYPE:
24712467
values = conversion.ensure_datetime64ns(values)
24722468

2473-
super(DatetimeBlock, self).__init__(values, fastpath=True,
2474-
placement=placement, **kwargs)
2469+
super(DatetimeBlock, self).__init__(values,
2470+
placement=placement, ndim=ndim)
24752471

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

2605-
def __init__(self, values, placement, ndim=2, **kwargs):
2601+
def __init__(self, values, placement, ndim=2, dtype=None):
26062602

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

2610-
dtype = kwargs.pop('dtype', None)
2611-
26122606
if dtype is not None:
26132607
if isinstance(dtype, compat.string_types):
26142608
dtype = DatetimeTZDtype.construct_from_string(dtype)
@@ -2618,7 +2612,7 @@ def __init__(self, values, placement, ndim=2, **kwargs):
26182612
raise ValueError("cannot create a DatetimeTZBlock without a tz")
26192613

26202614
super(DatetimeTZBlock, self).__init__(values, placement=placement,
2621-
ndim=ndim, **kwargs)
2615+
ndim=ndim)
26222616

26232617
def copy(self, deep=True, mgr=None):
26242618
""" copy constructor """
@@ -2824,7 +2818,7 @@ def copy(self, deep=True, mgr=None):
28242818

28252819
def make_block_same_class(self, values, placement, sparse_index=None,
28262820
kind=None, dtype=None, fill_value=None,
2827-
copy=False, fastpath=True, **kwargs):
2821+
copy=False, ndim=None):
28282822
""" return a new block """
28292823
if dtype is None:
28302824
dtype = values.dtype
@@ -2843,8 +2837,7 @@ def make_block_same_class(self, values, placement, sparse_index=None,
28432837
# won't take space since there's 0 items, plus it will preserve
28442838
# the dtype.
28452839
return self.make_block(np.empty(values.shape, dtype=dtype),
2846-
placement,
2847-
fastpath=True)
2840+
placement)
28482841
elif nitems > 1:
28492842
raise ValueError("Only 1-item 2d sparse blocks are supported")
28502843
else:
@@ -2853,7 +2846,7 @@ def make_block_same_class(self, values, placement, sparse_index=None,
28532846
new_values = SparseArray(values, sparse_index=sparse_index,
28542847
kind=kind or self.kind, dtype=dtype,
28552848
fill_value=fill_value, copy=copy)
2856-
return self.make_block(new_values, fastpath=fastpath,
2849+
return self.make_block(new_values,
28572850
placement=placement)
28582851

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

29632956

29642957
def make_block(values, placement, klass=None, ndim=None, dtype=None,
2965-
fastpath=False):
2958+
fastpath=None):
2959+
if fastpath is not None:
2960+
# GH#19265 pyarrow is passing this
2961+
warnings.warn("fastpath argument is deprecated, will be removed "
2962+
"in a future release.", DeprecationWarning)
29662963
if klass is None:
29672964
dtype = dtype or values.dtype
29682965
klass = get_block_type(values, dtype)
29692966

29702967
elif klass is DatetimeTZBlock and not is_datetimetz(values):
2971-
return klass(values, ndim=ndim, fastpath=fastpath,
2968+
return klass(values, ndim=ndim,
29722969
placement=placement, dtype=dtype)
29732970

2974-
return klass(values, ndim=ndim, fastpath=fastpath, placement=placement)
2971+
return klass(values, ndim=ndim, placement=placement)
29752972

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

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

3034-
def __init__(self, blocks, axes, do_integrity_check=True, fastpath=True):
3031+
def __init__(self, blocks, axes, do_integrity_check=True):
30353032
self.axes = [_ensure_index(ax) for ax in axes]
30363033
self.blocks = tuple(blocks)
30373034

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

3645-
bm = self.__class__(new_blocks, new_axes, do_integrity_check=False,
3646-
fastpath=True)
3642+
bm = self.__class__(new_blocks, new_axes, do_integrity_check=False)
36473643
bm._consolidate_inplace()
36483644
return bm
36493645

@@ -3798,7 +3794,7 @@ def xs(self, key, axis=1, copy=True, takeable=False):
37983794
# we must copy here as we are mixed type
37993795
for blk in self.blocks:
38003796
newb = make_block(values=blk.values[slicer],
3801-
klass=blk.__class__, fastpath=True,
3797+
klass=blk.__class__,
38023798
placement=blk.mgr_locs)
38033799
new_blocks.append(newb)
38043800
elif len(self.blocks) == 1:
@@ -3808,8 +3804,7 @@ def xs(self, key, axis=1, copy=True, takeable=False):
38083804
vals = vals.copy()
38093805
new_blocks = [make_block(values=vals,
38103806
placement=block.mgr_locs,
3811-
klass=block.__class__,
3812-
fastpath=True, )]
3807+
klass=block.__class__)]
38133808

38143809
return self.__class__(new_blocks, new_axes)
38153810

@@ -3912,7 +3907,7 @@ def iget(self, i, fastpath=True):
39123907
return SingleBlockManager(
39133908
[block.make_block_same_class(values,
39143909
placement=slice(0, len(values)),
3915-
ndim=1, fastpath=True)],
3910+
ndim=1)],
39163911
self.axes[1])
39173912

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

44364431
if not isinstance(block, Block):
4437-
block = make_block(block, placement=slice(0, len(axis)), ndim=1,
4438-
fastpath=True)
4432+
block = make_block(block, placement=slice(0, len(axis)), ndim=1)
44394433

44404434
self.blocks = [block]
44414435

@@ -4727,7 +4721,6 @@ def form_blocks(arrays, names, axes):
47274721
if len(items_dict['DatetimeTZBlock']):
47284722
dttz_blocks = [make_block(array,
47294723
klass=DatetimeTZBlock,
4730-
fastpath=True,
47314724
placement=[i])
47324725
for i, _, array in items_dict['DatetimeTZBlock']]
47334726
blocks.extend(dttz_blocks)
@@ -4745,8 +4738,7 @@ def form_blocks(arrays, names, axes):
47454738
blocks.extend(sparse_blocks)
47464739

47474740
if len(items_dict['CategoricalBlock']) > 0:
4748-
cat_blocks = [make_block(array, klass=CategoricalBlock, fastpath=True,
4749-
placement=[i])
4741+
cat_blocks = [make_block(array, klass=CategoricalBlock, placement=[i])
47504742
for i, _, array in items_dict['CategoricalBlock']]
47514743
blocks.extend(cat_blocks)
47524744

@@ -4802,8 +4794,7 @@ def _sparse_blockify(tuples, dtype=None):
48024794
new_blocks = []
48034795
for i, names, array in tuples:
48044796
array = _maybe_to_sparse(array)
4805-
block = make_block(array, klass=SparseBlock, fastpath=True,
4806-
placement=[i])
4797+
block = make_block(array, klass=SparseBlock, placement=[i])
48074798
new_blocks.append(block)
48084799

48094800
return new_blocks
@@ -4887,7 +4878,7 @@ def _merge_blocks(blocks, dtype=None, _can_consolidate=True):
48874878
new_values = new_values[argsort]
48884879
new_mgr_locs = new_mgr_locs[argsort]
48894880

4890-
return make_block(new_values, fastpath=True, placement=new_mgr_locs)
4881+
return make_block(new_values, placement=new_mgr_locs)
48914882

48924883
# no merge
48934884
return blocks

pandas/tests/internals/test_internals.py

+8
Original file line numberDiff line numberDiff line change
@@ -1253,3 +1253,11 @@ def test_binop_other(self, op, value, dtype):
12531253
result = op(s, e).dtypes
12541254
expected = op(s, value).dtypes
12551255
assert_series_equal(result, expected)
1256+
1257+
1258+
def test_deprecated_fastpath():
1259+
# GH#19265
1260+
values = np.random.rand(3, 3)
1261+
with tm.assert_produces_warning(DeprecationWarning,
1262+
check_stacklevel=False):
1263+
make_block(values, placement=np.arange(3), fastpath=True)

0 commit comments

Comments
 (0)