def set(self, item, value):
<EOL>value_is_extension_type = (is_extension_type(value) or<EOL>is_extension_array_dtype(value))<EOL>if value_is_extension_type:<EOL><INDENT>def value_getitem(placement):<EOL><INDENT>return value<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if value.ndim == self.ndim - <NUM_LIT:1>:<EOL><INDENT>value = _safe_reshape(value, (<NUM_LIT:1>,) + value.shape)<EOL>def value_getitem(placement):<EOL><INDENT>return value<EOL><DEDENT><DEDENT>else:<EOL><INDENT>def value_getitem(placement):<EOL><INDENT>return value[placement.indexer]<EOL><DEDENT><DEDENT>if value.shape[<NUM_LIT:1>:] != self.shape[<NUM_LIT:1>:]:<EOL><INDENT>raise AssertionError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>try:<EOL><INDENT>loc = self.items.get_loc(item)<EOL><DEDENT>except KeyError:<EOL><INDENT>self.insert(len(self.items), item, value)<EOL>return<EOL><DEDENT>if isinstance(loc, int):<EOL><INDENT>loc = [loc]<EOL><DEDENT>blknos = self._blknos[loc]<EOL>blklocs = self._blklocs[loc].copy()<EOL>unfit_mgr_locs = []<EOL>unfit_val_locs = []<EOL>removed_blknos = []<EOL>for blkno, val_locs in libinternals.get_blkno_placements(blknos,<EOL>self.nblocks,<EOL>group=True):<EOL><INDENT>blk = self.blocks[blkno]<EOL>blk_locs = blklocs[val_locs.indexer]<EOL>if blk.should_store(value):<EOL><INDENT>blk.set(blk_locs, value_getitem(val_locs))<EOL><DEDENT>else:<EOL><INDENT>unfit_mgr_locs.append(blk.mgr_locs.as_array[blk_locs])<EOL>unfit_val_locs.append(val_locs)<EOL>if len(val_locs) == len(blk.mgr_locs):<EOL><INDENT>removed_blknos.append(blkno)<EOL><DEDENT>else:<EOL><INDENT>self._blklocs[blk.mgr_locs.indexer] = -<NUM_LIT:1><EOL>blk.delete(blk_locs)<EOL>self._blklocs[blk.mgr_locs.indexer] = np.arange(len(blk))<EOL><DEDENT><DEDENT><DEDENT>if len(removed_blknos):<EOL><INDENT>is_deleted = np.zeros(self.nblocks, dtype=np.bool_)<EOL>is_deleted[removed_blknos] = True<EOL>new_blknos = np.empty(self.nblocks, dtype=np.int64)<EOL>new_blknos.fill(-<NUM_LIT:1>)<EOL>new_blknos[~is_deleted] = np.arange(self.nblocks -<EOL>len(removed_blknos))<EOL>self._blknos = algos.take_1d(new_blknos, self._blknos, axis=<NUM_LIT:0>,<EOL>allow_fill=False)<EOL>self.blocks = tuple(blk for i, blk in enumerate(self.blocks)<EOL>if i not in set(removed_blknos))<EOL><DEDENT>if unfit_val_locs:<EOL><INDENT>unfit_mgr_locs = np.concatenate(unfit_mgr_locs)<EOL>unfit_count = len(unfit_mgr_locs)<EOL>new_blocks = []<EOL>if value_is_extension_type:<EOL><INDENT>new_blocks.extend(<EOL>make_block(values=value.copy(), ndim=self.ndim,<EOL>placement=slice(mgr_loc, mgr_loc + <NUM_LIT:1>))<EOL>for mgr_loc in unfit_mgr_locs)<EOL>self._blknos[unfit_mgr_locs] = (np.arange(unfit_count) +<EOL>len(self.blocks))<EOL>self._blklocs[unfit_mgr_locs] = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>unfit_val_items = unfit_val_locs[<NUM_LIT:0>].append(unfit_val_locs[<NUM_LIT:1>:])<EOL>new_blocks.append(<EOL>make_block(values=value_getitem(unfit_val_items),<EOL>ndim=self.ndim, placement=unfit_mgr_locs))<EOL>self._blknos[unfit_mgr_locs] = len(self.blocks)<EOL>self._blklocs[unfit_mgr_locs] = np.arange(unfit_count)<EOL><DEDENT>self.blocks += tuple(new_blocks)<EOL>self._known_consolidated = False<EOL><DEDENT>
Set new item in-place. Does not consolidate. Adds new Block if not
contained in the current set of items