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

Method _iset_split_block

pandas/core/internals/managers.py:1430–1480  ·  view source on GitHub ↗

Removes columns from a block by splitting the block. Avoids copying the whole block through slicing and updates the manager after determining the new block structure. Optionally adds a new block, otherwise has to be done by the caller. Parameters ----------

(
        self,
        blkno_l: int,
        blk_locs: np.ndarray | list[int],
        value: ArrayLike | None = None,
        refs: BlockValuesRefs | None = None,
    )

Source from the content-addressed store, hash-verified

1428 self._known_consolidated = False
1429
1430 def _iset_split_block(
1431 self,
1432 blkno_l: int,
1433 blk_locs: np.ndarray | list[int],
1434 value: ArrayLike | None = None,
1435 refs: BlockValuesRefs | None = None,
1436 ) -> None:
1437 """Removes columns from a block by splitting the block.
1438
1439 Avoids copying the whole block through slicing and updates the manager
1440 after determining the new block structure. Optionally adds a new block,
1441 otherwise has to be done by the caller.
1442
1443 Parameters
1444 ----------
1445 blkno_l: The block number to operate on, relevant for updating the manager
1446 blk_locs: The locations of our block that should be deleted.
1447 value: The value to set as a replacement.
1448 refs: The reference tracking object of the value to set.
1449 """
1450 blk = self.blocks[blkno_l]
1451
1452 if self._blklocs is None:
1453 self._rebuild_blknos_and_blklocs()
1454
1455 nbs_tup = tuple(blk.delete(blk_locs))
1456 if value is not None:
1457 locs = blk.mgr_locs.as_array[blk_locs]
1458 first_nb = new_block_2d(value, BlockPlacement(locs), refs=refs)
1459 else:
1460 first_nb = nbs_tup[0]
1461 nbs_tup = tuple(nbs_tup[1:])
1462
1463 nr_blocks = len(self.blocks)
1464 blocks_tup = (
1465 *self.blocks[:blkno_l],
1466 first_nb,
1467 *self.blocks[blkno_l + 1 :],
1468 *nbs_tup,
1469 )
1470 self.blocks = blocks_tup
1471
1472 if not nbs_tup and value is not None:
1473 # No need to update anything if split did not happen
1474 return
1475
1476 self._blklocs[first_nb.mgr_locs.indexer] = np.arange(len(first_nb))
1477
1478 for i, nb in enumerate(nbs_tup):
1479 self._blklocs[nb.mgr_locs.indexer] = np.arange(len(nb))
1480 self._blknos[nb.mgr_locs.indexer] = i + nr_blocks
1481
1482 def _iset_single(
1483 self,

Callers 5

isetMethod · 0.95
column_setitemMethod · 0.95
setitemMethod · 0.80
test_iset_split_blockMethod · 0.80

Calls 2

new_block_2dFunction · 0.90
deleteMethod · 0.45

Tested by 2

test_iset_split_blockMethod · 0.64