Set new item in-place. Does not consolidate. Adds new Block if not contained in the current set of items
(
self,
loc: int | slice | np.ndarray,
value: ArrayLike,
inplace: bool = False,
refs: BlockValuesRefs | None = None,
)
| 1278 | return result # type: ignore[return-value] |
| 1279 | |
| 1280 | def iset( |
| 1281 | self, |
| 1282 | loc: int | slice | np.ndarray, |
| 1283 | value: ArrayLike, |
| 1284 | inplace: bool = False, |
| 1285 | refs: BlockValuesRefs | None = None, |
| 1286 | ) -> None: |
| 1287 | """ |
| 1288 | Set new item in-place. Does not consolidate. Adds new Block if not |
| 1289 | contained in the current set of items |
| 1290 | """ |
| 1291 | |
| 1292 | # FIXME: refactor, clearly separate broadcasting & zip-like assignment |
| 1293 | # can prob also fix the various if tests for sparse/categorical |
| 1294 | if self._blklocs is None and self.ndim > 1: |
| 1295 | self._rebuild_blknos_and_blklocs() |
| 1296 | |
| 1297 | # Note: we exclude DTA/TDA here |
| 1298 | value_is_extension_type = is_1d_only_ea_dtype(value.dtype) |
| 1299 | if not value_is_extension_type: |
| 1300 | if value.ndim == 2: |
| 1301 | value = value.T |
| 1302 | else: |
| 1303 | value = ensure_block_shape(value, ndim=2) |
| 1304 | |
| 1305 | if value.shape[1:] != self.shape[1:]: |
| 1306 | raise AssertionError( |
| 1307 | "Shape of new values must be compatible with manager shape" |
| 1308 | ) |
| 1309 | |
| 1310 | if lib.is_integer(loc): |
| 1311 | # We have 6 tests where loc is _not_ an int. |
| 1312 | # In this case, get_blkno_placements will yield only one tuple, |
| 1313 | # containing (self._blknos[loc], BlockPlacement(slice(0, 1, 1))) |
| 1314 | |
| 1315 | # Check if we can use _iset_single fastpath |
| 1316 | loc = cast(int, loc) |
| 1317 | blkno = self.blknos[loc] |
| 1318 | blk = self.blocks[blkno] |
| 1319 | if len(blk._mgr_locs) == 1: # TODO: fastest way to check this? |
| 1320 | return self._iset_single( |
| 1321 | loc, |
| 1322 | value, |
| 1323 | inplace=inplace, |
| 1324 | blkno=blkno, |
| 1325 | blk=blk, |
| 1326 | refs=refs, |
| 1327 | ) |
| 1328 | |
| 1329 | # error: Incompatible types in assignment (expression has type |
| 1330 | # "List[Union[int, slice, ndarray]]", variable has type "Union[int, |
| 1331 | # slice, ndarray]") |
| 1332 | loc = [loc] # type: ignore[assignment] |
| 1333 | |
| 1334 | # categorical/sparse/datetimetz |
| 1335 | if value_is_extension_type: |
| 1336 | |
| 1337 | def value_getitem(placement): |