MCPcopy
hub / github.com/pandas-dev/pandas / _combine

Method _combine

pandas/core/internals/managers.py:705–733  ·  view source on GitHub ↗

return a new manager with the blocks

(self, blocks: list[Block], index: Index | None = None)

Source from the content-addressed store, hash-verified

703 return self._combine(numeric_blocks)
704
705 def _combine(self, blocks: list[Block], index: Index | None = None) -> Self:
706 """return a new manager with the blocks"""
707 if len(blocks) == 0:
708 if self.ndim == 2:
709 # retain our own Index dtype
710 if index is not None:
711 axes = [self.items[:0], index]
712 else:
713 axes = [self.items[:0], *self.axes[1:]]
714 return self.make_empty(axes)
715 return self.make_empty()
716
717 # FIXME: optimization potential
718 indexer = np.sort(np.concatenate([b.mgr_locs.as_array for b in blocks]))
719 inv_indexer = lib.get_reverse_indexer(indexer, self.shape[0])
720
721 new_blocks: list[Block] = []
722 for b in blocks:
723 nb = b.copy(deep=False)
724 nb.mgr_locs = BlockPlacement(inv_indexer[nb.mgr_locs.indexer])
725 new_blocks.append(nb)
726
727 axes = list(self.axes)
728 # TODO shallow copy of axes?
729 if index is not None:
730 axes[-1] = index
731 axes[0] = self.items.take(indexer)
732
733 return type(self).from_blocks(new_blocks, axes)
734
735 @property
736 def nblocks(self) -> int:

Callers 4

_get_data_subsetMethod · 0.95
get_bool_dataMethod · 0.95
get_numeric_dataMethod · 0.95
to_iter_dictMethod · 0.45

Calls 5

make_emptyMethod · 0.95
copyMethod · 0.45
appendMethod · 0.45
takeMethod · 0.45
from_blocksMethod · 0.45

Tested by

no test coverage detected