From af554cca69c1472c4dcee07a127370b90a49b862 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 25 Jun 2019 07:43:46 -0700 Subject: [PATCH 1/3] Remove no-longer-used BlockManager.xs --- pandas/core/internals/managers.py | 42 ------------------------ pandas/core/panel.py | 8 +---- pandas/tests/internals/test_internals.py | 15 --------- 3 files changed, 1 insertion(+), 64 deletions(-) diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index 592c385dd87ec..923624c3f680b 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -821,48 +821,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 diff --git a/pandas/core/panel.py b/pandas/core/panel.py index 9d6b7333ca39f..c0340fc975a7e 100644 --- a/pandas/core/panel.py +++ b/pandas/core/panel.py @@ -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") _xs = xs diff --git a/pandas/tests/internals/test_internals.py b/pandas/tests/internals/test_internals.py index fbd821f8ec342..b997e2b6eec8f 100644 --- a/pandas/tests/internals/test_internals.py +++ b/pandas/tests/internals/test_internals.py @@ -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', From 00e5c917d57a16639f1bfa3604e620ee9de546fd Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 25 Jun 2019 08:46:00 -0700 Subject: [PATCH 2/3] remove unreachable casting code --- pandas/core/internals/blocks.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 4cc6c86417b3b..e1488dca57e3a 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -653,24 +653,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 From 9432501f4bfd66af9e14b53628612e5308244f7e Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 25 Jun 2019 17:17:40 -0700 Subject: [PATCH 3/3] dummy commit to force CI