Skip to content

CLN: Remove no-longer-used BlockManager.xs #27043

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
Jun 26, 2019
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
17 changes: 3 additions & 14 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,24 +647,13 @@ def _try_cast_result(self, result, dtype=None):
if self.is_integer or self.is_bool or self.is_datetime:
pass
elif self.is_float and result.dtype == self.dtype:

# protect against a bool/object showing up here
if isinstance(dtype, str) and dtype == 'infer':
return result
if not isinstance(dtype, type):
dtype = dtype.type
if issubclass(dtype, (np.bool_, np.object_)):
if issubclass(dtype, np.bool_):
if isna(result).all():
return result.astype(np.bool_)
else:
result = result.astype(np.object_)
result[result == 1] = True
result[result == 0] = False
return result
else:
return result.astype(np.object_)

# This is only reached via Block.setitem, where dtype is always
# either "infer", self.dtype, or values.dtype.
assert dtype == self.dtype, (dtype, self.dtype)
return result

# may need to change the dtype here
Expand Down
42 changes: 0 additions & 42 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,48 +816,6 @@ def to_dict(self, copy=True):
return {dtype: self.combine(blocks, copy=copy)
for dtype, blocks in bd.items()}

def xs(self, key, axis=1, copy=True, takeable=False):
if axis < 1:
raise AssertionError(
'Can only take xs across axis >= 1, got {ax}'.format(ax=axis))

# take by position
if takeable:
loc = key
else:
loc = self.axes[axis].get_loc(key)

slicer = [slice(None, None) for _ in range(self.ndim)]
slicer[axis] = loc
slicer = tuple(slicer)

new_axes = list(self.axes)

# could be an array indexer!
if isinstance(loc, (slice, np.ndarray)):
new_axes[axis] = new_axes[axis][loc]
else:
new_axes.pop(axis)

new_blocks = []
if len(self.blocks) > 1:
# we must copy here as we are mixed type
for blk in self.blocks:
newb = make_block(values=blk.values[slicer],
klass=blk.__class__,
placement=blk.mgr_locs)
new_blocks.append(newb)
elif len(self.blocks) == 1:
block = self.blocks[0]
vals = block.values[slicer]
if copy:
vals = vals.copy()
new_blocks = [make_block(values=vals,
placement=block.mgr_locs,
klass=block.__class__)]

return self.__class__(new_blocks, new_axes)

def fast_xs(self, loc):
"""
get a cross sectional for a given location in the
Expand Down
8 changes: 1 addition & 7 deletions pandas/core/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,13 +856,7 @@ def xs(self, key, axis=1):
if axis == 0:
return self[key]

self._consolidate_inplace()
axis_number = self._get_axis_number(axis)
new_data = self._data.xs(key, axis=axis_number, copy=False)
result = self._construct_return_type(new_data)
copy = new_data.is_mixed_type
result._set_is_copy(self, copy=copy)
return result
raise NotImplementedError("Panel is removed in pandas 0.25.0")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this code hit? I'm confused by the reference to panel.

Copy link
Member Author

Choose a reason for hiding this comment

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

We've removed most of the Panel tests, but not yet all of Panel itself. So this is just explicitly-disabling a method that would call BlockManager.xs, since we're on the road towards removing the class anyway.


_xs = xs

Expand Down
15 changes: 0 additions & 15 deletions pandas/tests/internals/test_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,21 +705,6 @@ def test_reindex_items(self):
mgr.get('d').internal_values(),
reindexed.get('d').internal_values())

def test_multiindex_xs(self):
mgr = create_mgr('a,b,c: f8; d,e,f: i8')

index = MultiIndex(levels=[['foo', 'bar', 'baz', 'qux'], ['one', 'two',
'three']],
codes=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3],
[0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],
names=['first', 'second'])

mgr.set_axis(1, index)
result = mgr.xs('bar', axis=1)
assert result.shape == (6, 2)
assert result.axes[1][0] == ('bar', 'one')
assert result.axes[1][1] == ('bar', 'two')

def test_get_numeric_data(self):
mgr = create_mgr('int: int; float: float; complex: complex;'
'str: object; bool: bool; obj: object; dt: datetime',
Expand Down