Set values ("setitem") into a single column (not setting the full column). This is a method on the BlockManager level, to avoid creating an intermediate Series at the DataFrame level (`s = df[loc]; s[idx] = value`)
(
self, loc: int, idx: int | slice | np.ndarray, value, inplace_only: bool = False
)
| 1510 | return |
| 1511 | |
| 1512 | def column_setitem( |
| 1513 | self, loc: int, idx: int | slice | np.ndarray, value, inplace_only: bool = False |
| 1514 | ) -> None: |
| 1515 | """ |
| 1516 | Set values ("setitem") into a single column (not setting the full column). |
| 1517 | |
| 1518 | This is a method on the BlockManager level, to avoid creating an |
| 1519 | intermediate Series at the DataFrame level (`s = df[loc]; s[idx] = value`) |
| 1520 | """ |
| 1521 | if not self._has_no_reference(loc): |
| 1522 | blkno = self.blknos[loc] |
| 1523 | # Split blocks to only copy the column we want to modify |
| 1524 | blk_loc = self.blklocs[loc] |
| 1525 | # Copy our values |
| 1526 | values = self.blocks[blkno].values |
| 1527 | if values.ndim == 1: |
| 1528 | values = values.copy() |
| 1529 | else: |
| 1530 | # Use [blk_loc] as indexer to keep ndim=2, this already results in a |
| 1531 | # copy |
| 1532 | values = values[[blk_loc]] |
| 1533 | self._iset_split_block(blkno, [blk_loc], values) |
| 1534 | |
| 1535 | # this manager is only created temporarily to mutate the values in place |
| 1536 | # so don't track references, otherwise the `setitem` would perform CoW again |
| 1537 | col_mgr = self.iget(loc, track_ref=False) |
| 1538 | if inplace_only: |
| 1539 | col_mgr.setitem_inplace(idx, value) |
| 1540 | else: |
| 1541 | new_mgr = col_mgr.setitem((idx,), value) |
| 1542 | self.iset(loc, new_mgr._block.values, inplace=True) |
| 1543 | |
| 1544 | def insert(self, loc: int, item: Hashable, value: ArrayLike, refs=None) -> None: |
| 1545 | """ |
no test coverage detected