Skip to content

Commit ff50b46

Browse files
jbrockmendelTomAugspurger
authored andcommitted
CLN: Remove no-longer-used BlockManager.xs (pandas-dev#27043)
* Remove no-longer-used BlockManager.xs
1 parent a7f1d69 commit ff50b46

File tree

4 files changed

+4
-78
lines changed

4 files changed

+4
-78
lines changed

pandas/core/internals/blocks.py

+3-14
Original file line numberDiff line numberDiff line change
@@ -647,24 +647,13 @@ def _try_cast_result(self, result, dtype=None):
647647
if self.is_integer or self.is_bool or self.is_datetime:
648648
pass
649649
elif self.is_float and result.dtype == self.dtype:
650-
651650
# protect against a bool/object showing up here
652651
if isinstance(dtype, str) and dtype == 'infer':
653652
return result
654-
if not isinstance(dtype, type):
655-
dtype = dtype.type
656-
if issubclass(dtype, (np.bool_, np.object_)):
657-
if issubclass(dtype, np.bool_):
658-
if isna(result).all():
659-
return result.astype(np.bool_)
660-
else:
661-
result = result.astype(np.object_)
662-
result[result == 1] = True
663-
result[result == 0] = False
664-
return result
665-
else:
666-
return result.astype(np.object_)
667653

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

670659
# may need to change the dtype here

pandas/core/internals/managers.py

-42
Original file line numberDiff line numberDiff line change
@@ -816,48 +816,6 @@ def to_dict(self, copy=True):
816816
return {dtype: self.combine(blocks, copy=copy)
817817
for dtype, blocks in bd.items()}
818818

819-
def xs(self, key, axis=1, copy=True, takeable=False):
820-
if axis < 1:
821-
raise AssertionError(
822-
'Can only take xs across axis >= 1, got {ax}'.format(ax=axis))
823-
824-
# take by position
825-
if takeable:
826-
loc = key
827-
else:
828-
loc = self.axes[axis].get_loc(key)
829-
830-
slicer = [slice(None, None) for _ in range(self.ndim)]
831-
slicer[axis] = loc
832-
slicer = tuple(slicer)
833-
834-
new_axes = list(self.axes)
835-
836-
# could be an array indexer!
837-
if isinstance(loc, (slice, np.ndarray)):
838-
new_axes[axis] = new_axes[axis][loc]
839-
else:
840-
new_axes.pop(axis)
841-
842-
new_blocks = []
843-
if len(self.blocks) > 1:
844-
# we must copy here as we are mixed type
845-
for blk in self.blocks:
846-
newb = make_block(values=blk.values[slicer],
847-
klass=blk.__class__,
848-
placement=blk.mgr_locs)
849-
new_blocks.append(newb)
850-
elif len(self.blocks) == 1:
851-
block = self.blocks[0]
852-
vals = block.values[slicer]
853-
if copy:
854-
vals = vals.copy()
855-
new_blocks = [make_block(values=vals,
856-
placement=block.mgr_locs,
857-
klass=block.__class__)]
858-
859-
return self.__class__(new_blocks, new_axes)
860-
861819
def fast_xs(self, loc):
862820
"""
863821
get a cross sectional for a given location in the

pandas/core/panel.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -856,13 +856,7 @@ def xs(self, key, axis=1):
856856
if axis == 0:
857857
return self[key]
858858

859-
self._consolidate_inplace()
860-
axis_number = self._get_axis_number(axis)
861-
new_data = self._data.xs(key, axis=axis_number, copy=False)
862-
result = self._construct_return_type(new_data)
863-
copy = new_data.is_mixed_type
864-
result._set_is_copy(self, copy=copy)
865-
return result
859+
raise NotImplementedError("Panel is removed in pandas 0.25.0")
866860

867861
_xs = xs
868862

pandas/tests/internals/test_internals.py

-15
Original file line numberDiff line numberDiff line change
@@ -705,21 +705,6 @@ def test_reindex_items(self):
705705
mgr.get('d').internal_values(),
706706
reindexed.get('d').internal_values())
707707

708-
def test_multiindex_xs(self):
709-
mgr = create_mgr('a,b,c: f8; d,e,f: i8')
710-
711-
index = MultiIndex(levels=[['foo', 'bar', 'baz', 'qux'], ['one', 'two',
712-
'three']],
713-
codes=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3],
714-
[0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],
715-
names=['first', 'second'])
716-
717-
mgr.set_axis(1, index)
718-
result = mgr.xs('bar', axis=1)
719-
assert result.shape == (6, 2)
720-
assert result.axes[1][0] == ('bar', 'one')
721-
assert result.axes[1][1] == ('bar', 'two')
722-
723708
def test_get_numeric_data(self):
724709
mgr = create_mgr('int: int; float: float; complex: complex;'
725710
'str: object; bool: bool; obj: object; dt: datetime',

0 commit comments

Comments
 (0)