return a new manager with the blocks
(self, blocks: list[Block], index: Index | None = None)
| 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: |
no test coverage detected