From a1dba52a5dc6fbb21847ed0df48729f323f40b69 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 11 Jun 2019 17:48:30 -0700 Subject: [PATCH 1/2] Remove unused asobject --- pandas/core/internals/managers.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index 0b63588c9f5d9..35ed5710f1fcf 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -1553,14 +1553,6 @@ def get_values(self): """ return a dense type view """ return np.array(self._block.to_dense(), copy=False) - @property - def asobject(self): - """ - return a object dtype array. datetime/timedelta like values are boxed - to Timestamp/Timedelta instances. - """ - return self._block.get_values(dtype=object) - @property def _can_hold_na(self): return self._block._can_hold_na From 331c3a2a37b88cefc44493565248e5c79fb4290c Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 11 Jun 2019 19:25:54 -0700 Subject: [PATCH 2/2] remove unreachable code in internals --- pandas/core/internals/blocks.py | 15 +++++---------- pandas/core/internals/managers.py | 30 +++--------------------------- 2 files changed, 8 insertions(+), 37 deletions(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index f86ef40a97299..f9178959d8272 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -417,17 +417,14 @@ def split_and_operate(self, mask, f, inplace): new_values = self.values def make_a_block(nv, ref_loc): - if isinstance(nv, Block): - block = nv - elif isinstance(nv, list): + if isinstance(nv, list): + assert len(nv) == 1, nv + assert isinstance(nv[0], Block) block = nv[0] else: # Put back the dimension that was taken from it and make # a block out of the result. - try: - nv = _block_shape(nv, ndim=self.ndim) - except (AttributeError, NotImplementedError): - pass + nv = _block_shape(nv, ndim=self.ndim) block = self.make_block(values=nv, placement=ref_loc) return block @@ -2629,10 +2626,10 @@ def f(m, v, i): values = fn(v.ravel(), **fn_kwargs) try: values = values.reshape(shape) - values = _block_shape(values, ndim=self.ndim) except (AttributeError, NotImplementedError): pass + values = _block_shape(values, ndim=self.ndim) return values if by_item and not self._is_single_block: @@ -3168,8 +3165,6 @@ def _putmask_smart(v, m, n): # n should be the length of the mask or a scalar here if not is_list_like(n): n = np.repeat(n, len(m)) - elif isinstance(n, np.ndarray) and n.ndim == 0: # numpy scalar - n = np.repeat(np.array(n, ndmin=1), len(m)) # see if we are only masking values that if putted # will work in the current dtype diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index 35ed5710f1fcf..6f0e8a909d36f 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -433,11 +433,11 @@ def quantile(self, axis=0, consolidate=True, transposed=False, self._consolidate_inplace() def get_axe(block, qs, axes): + # Because Series dispatches to DataFrame, we will always have + # block.ndim == 2 from pandas import Float64Index if is_list_like(qs): ax = Float64Index(qs) - elif block.ndim == 1: - ax = Float64Index([qs]) else: ax = axes[0] return ax @@ -1345,27 +1345,6 @@ def take(self, indexer, axis=1, verify=True, convert=True): return self.reindex_indexer(new_axis=new_labels, indexer=indexer, axis=axis, allow_dups=True) - def merge(self, other, lsuffix='', rsuffix=''): - # 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]) - - new_blocks = [blk.copy(deep=False) for blk in self.blocks] - - offset = self.shape[0] - for blk in other.blocks: - blk = blk.copy(deep=False) - blk.mgr_locs = blk.mgr_locs.add(offset) - new_blocks.append(blk) - - new_axes = list(self.axes) - new_axes[0] = new_items - - return self.__class__(_consolidate(new_blocks), new_axes) - def equals(self, other): self_axes, other_axes = self.axes, other.axes if len(self_axes) != len(other_axes): @@ -1941,10 +1920,7 @@ def _compare_or_regex_search(a, b, regex=False): return result -def _concat_indexes(indexes): - return indexes[0].append(indexes[1:]) - - +# TODO: this is no longer used in this module, could be moved to concat def items_overlap_with_suffix(left, lsuffix, right, rsuffix): """ If two indices overlap, add suffixes to overlapping entries.