Skip to content

CLN: Remove Unneeded BlockManager methods #22002

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 5 commits into from
Jul 26, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
27 changes: 9 additions & 18 deletions pandas/_libs/internals.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ cdef class BlockPlacement:
def __init__(self, val):
cdef slice slc

self._as_slice = None
self._as_array = None
self._has_slice = False
self._has_array = False

Expand Down Expand Up @@ -144,6 +146,7 @@ cdef class BlockPlacement:
other_int = <Py_ssize_t>other

if other_int == 0:
# BlockPlacement is treated as immutable
return self

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

if stop < 0:
self._as_slice = slice(start, None, step)
val = slice(start, None, step)
else:
self._as_slice = slice(start, stop, step)
val = slice(start, stop, step)

self._has_array = False
self._as_array = None
return BlockPlacement(val)
else:
newarr = self.as_array + other
if (newarr < 0).any():
raise ValueError("iadd causes length change")

self._as_array = newarr
self._has_array = True
self._has_slice = False
self._as_slice = None

return self

cdef BlockPlacement copy(self):
cdef slice s = self._ensure_has_slice()
if s is not None:
return BlockPlacement(s)
else:
return BlockPlacement(self._as_array)
val = newarr
return BlockPlacement(val)

def add(self, other):
return self.copy().iadd(other)
return self.iadd(other)

def sub(self, other):
return self.add(-other)
Expand Down
35 changes: 3 additions & 32 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class BlockManager(PandasObject):
get_slice(slice_like, axis)
get(label)
iget(loc)
get_scalar(label_tup)

take(indexer, axis)
reindex_axis(new_labels, axis)
Expand Down Expand Up @@ -993,21 +992,6 @@ def iget(self, i, fastpath=True):
ndim=1)],
self.axes[1])

def get_scalar(self, tup):
"""
Retrieve single item
"""
full_loc = [ax.get_loc(x) for ax, x in zip(self.axes, tup)]
blk = self.blocks[self._blknos[full_loc[0]]]
values = blk.values

# FIXME: this may return non-upcasted types?
if values.ndim == 1:
return values[full_loc[1]]

full_loc[0] = self._blklocs[full_loc[0]]
return values[tuple(full_loc)]

def delete(self, item):
"""
Delete selected item (items if non-unique) in-place.
Expand Down Expand Up @@ -1382,9 +1366,9 @@ def take(self, indexer, axis=1, verify=True, convert=True):
axis=axis, allow_dups=True)

def merge(self, other, lsuffix='', rsuffix=''):
if not self._is_indexed_like(other):
raise AssertionError('Must have same axes to merge managers')

# We assume at this point that the axes of self and other match.
# This is only called from Panel.join, which reindexes prior
# to calling to ensure this assumption holds.
l, r = items_overlap_with_suffix(left=self.items, lsuffix=lsuffix,
right=other.items, rsuffix=rsuffix)
new_items = _concat_indexes([l, r])
Expand All @@ -1402,19 +1386,6 @@ def merge(self, other, lsuffix='', rsuffix=''):

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

def _is_indexed_like(self, other):
"""
Check all axes except items
"""
if self.ndim != other.ndim:
raise AssertionError(
'Number of dimensions must agree got {ndim} and '
'{oth_ndim}'.format(ndim=self.ndim, oth_ndim=other.ndim))
for ax, oax in zip(self.axes[1:], other.axes[1:]):
if not ax.equals(oax):
return False
return True

def equals(self, other):
self_axes, other_axes = self.axes, other.axes
if len(self_axes) != len(other_axes):
Expand Down
20 changes: 0 additions & 20 deletions pandas/tests/internals/test_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,17 +329,6 @@ def test_is_mixed_dtype(self):
assert create_mgr('a,b:f8; c,d: f4').is_mixed_type
assert create_mgr('a,b:f8; c,d: object').is_mixed_type

def test_is_indexed_like(self):
mgr1 = create_mgr('a,b: f8')
mgr2 = create_mgr('a:i8; b:bool')
mgr3 = create_mgr('a,b,c: f8')
assert mgr1._is_indexed_like(mgr1)
assert mgr1._is_indexed_like(mgr2)
assert mgr1._is_indexed_like(mgr3)

assert not mgr1._is_indexed_like(mgr1.get_slice(
slice(-1), axis=1))

def test_duplicate_ref_loc_failure(self):
tmp_mgr = create_mgr('a:bool; a: f8')

Expand Down Expand Up @@ -396,15 +385,6 @@ def test_categorical_block_pickle(self):
smgr2 = tm.round_trip_pickle(smgr)
assert_series_equal(Series(smgr), Series(smgr2))

def test_get_scalar(self, mgr):
for item in mgr.items:
for i, index in enumerate(mgr.axes[1]):
res = mgr.get_scalar((item, index))
exp = mgr.get(item, fastpath=False)[i]
assert res == exp
exp = mgr.get(item).internal_values()[i]
assert res == exp

def test_get(self):
cols = Index(list('abc'))
values = np.random.rand(3, 3)
Expand Down