Skip to content

Commit 7110a34

Browse files
jbrockmendeljreback
authored andcommitted
CLN: Remove Unneeded BlockManager methods (#22002)
1 parent 377caeb commit 7110a34

File tree

3 files changed

+12
-70
lines changed

3 files changed

+12
-70
lines changed

pandas/_libs/internals.pyx

+9-18
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ cdef class BlockPlacement:
3232
def __init__(self, val):
3333
cdef slice slc
3434

35+
self._as_slice = None
36+
self._as_array = None
3537
self._has_slice = False
3638
self._has_array = False
3739

@@ -144,6 +146,7 @@ cdef class BlockPlacement:
144146
other_int = <Py_ssize_t>other
145147

146148
if other_int == 0:
149+
# BlockPlacement is treated as immutable
147150
return self
148151

149152
start, stop, step, l = slice_get_indices_ex(s)
@@ -155,33 +158,21 @@ cdef class BlockPlacement:
155158
raise ValueError("iadd causes length change")
156159

157160
if stop < 0:
158-
self._as_slice = slice(start, None, step)
161+
val = slice(start, None, step)
159162
else:
160-
self._as_slice = slice(start, stop, step)
163+
val = slice(start, stop, step)
161164

162-
self._has_array = False
163-
self._as_array = None
165+
return BlockPlacement(val)
164166
else:
165167
newarr = self.as_array + other
166168
if (newarr < 0).any():
167169
raise ValueError("iadd causes length change")
168170

169-
self._as_array = newarr
170-
self._has_array = True
171-
self._has_slice = False
172-
self._as_slice = None
173-
174-
return self
175-
176-
cdef BlockPlacement copy(self):
177-
cdef slice s = self._ensure_has_slice()
178-
if s is not None:
179-
return BlockPlacement(s)
180-
else:
181-
return BlockPlacement(self._as_array)
171+
val = newarr
172+
return BlockPlacement(val)
182173

183174
def add(self, other):
184-
return self.copy().iadd(other)
175+
return self.iadd(other)
185176

186177
def sub(self, other):
187178
return self.add(-other)

pandas/core/internals/managers.py

+3-32
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ class BlockManager(PandasObject):
8282
get_slice(slice_like, axis)
8383
get(label)
8484
iget(loc)
85-
get_scalar(label_tup)
8685
8786
take(indexer, axis)
8887
reindex_axis(new_labels, axis)
@@ -993,21 +992,6 @@ def iget(self, i, fastpath=True):
993992
ndim=1)],
994993
self.axes[1])
995994

996-
def get_scalar(self, tup):
997-
"""
998-
Retrieve single item
999-
"""
1000-
full_loc = [ax.get_loc(x) for ax, x in zip(self.axes, tup)]
1001-
blk = self.blocks[self._blknos[full_loc[0]]]
1002-
values = blk.values
1003-
1004-
# FIXME: this may return non-upcasted types?
1005-
if values.ndim == 1:
1006-
return values[full_loc[1]]
1007-
1008-
full_loc[0] = self._blklocs[full_loc[0]]
1009-
return values[tuple(full_loc)]
1010-
1011995
def delete(self, item):
1012996
"""
1013997
Delete selected item (items if non-unique) in-place.
@@ -1382,9 +1366,9 @@ def take(self, indexer, axis=1, verify=True, convert=True):
13821366
axis=axis, allow_dups=True)
13831367

13841368
def merge(self, other, lsuffix='', rsuffix=''):
1385-
if not self._is_indexed_like(other):
1386-
raise AssertionError('Must have same axes to merge managers')
1387-
1369+
# We assume at this point that the axes of self and other match.
1370+
# This is only called from Panel.join, which reindexes prior
1371+
# to calling to ensure this assumption holds.
13881372
l, r = items_overlap_with_suffix(left=self.items, lsuffix=lsuffix,
13891373
right=other.items, rsuffix=rsuffix)
13901374
new_items = _concat_indexes([l, r])
@@ -1402,19 +1386,6 @@ def merge(self, other, lsuffix='', rsuffix=''):
14021386

14031387
return self.__class__(_consolidate(new_blocks), new_axes)
14041388

1405-
def _is_indexed_like(self, other):
1406-
"""
1407-
Check all axes except items
1408-
"""
1409-
if self.ndim != other.ndim:
1410-
raise AssertionError(
1411-
'Number of dimensions must agree got {ndim} and '
1412-
'{oth_ndim}'.format(ndim=self.ndim, oth_ndim=other.ndim))
1413-
for ax, oax in zip(self.axes[1:], other.axes[1:]):
1414-
if not ax.equals(oax):
1415-
return False
1416-
return True
1417-
14181389
def equals(self, other):
14191390
self_axes, other_axes = self.axes, other.axes
14201391
if len(self_axes) != len(other_axes):

pandas/tests/internals/test_internals.py

-20
Original file line numberDiff line numberDiff line change
@@ -329,17 +329,6 @@ def test_is_mixed_dtype(self):
329329
assert create_mgr('a,b:f8; c,d: f4').is_mixed_type
330330
assert create_mgr('a,b:f8; c,d: object').is_mixed_type
331331

332-
def test_is_indexed_like(self):
333-
mgr1 = create_mgr('a,b: f8')
334-
mgr2 = create_mgr('a:i8; b:bool')
335-
mgr3 = create_mgr('a,b,c: f8')
336-
assert mgr1._is_indexed_like(mgr1)
337-
assert mgr1._is_indexed_like(mgr2)
338-
assert mgr1._is_indexed_like(mgr3)
339-
340-
assert not mgr1._is_indexed_like(mgr1.get_slice(
341-
slice(-1), axis=1))
342-
343332
def test_duplicate_ref_loc_failure(self):
344333
tmp_mgr = create_mgr('a:bool; a: f8')
345334

@@ -396,15 +385,6 @@ def test_categorical_block_pickle(self):
396385
smgr2 = tm.round_trip_pickle(smgr)
397386
assert_series_equal(Series(smgr), Series(smgr2))
398387

399-
def test_get_scalar(self, mgr):
400-
for item in mgr.items:
401-
for i, index in enumerate(mgr.axes[1]):
402-
res = mgr.get_scalar((item, index))
403-
exp = mgr.get(item, fastpath=False)[i]
404-
assert res == exp
405-
exp = mgr.get(item).internal_values()[i]
406-
assert res == exp
407-
408388
def test_get(self):
409389
cols = Index(list('abc'))
410390
values = np.random.rand(3, 3)

0 commit comments

Comments
 (0)