def insert(self, loc, item, value, allow_duplicates=False):
        """
        Insert item at selected position.

        Parameters
        ----------
        loc : int
        item : hashable
        value : array_like
        allow_duplicates: bool
            If False, trying to insert non-unique item will raise

        """
        if not allow_duplicates and item in self.items:
            # Should this be a different kind of error??
            raise ValueError('cannot insert {}, already exists'.format(item))

        if not isinstance(loc, int):
            raise TypeError("loc must be int")

        # insert to the axis; this could possibly raise a TypeError
        new_axis = self.items.insert(loc, item)

        block = make_block(values=value, ndim=self.ndim,
                           placement=slice(loc, loc + 1))

        for blkno, count in _fast_count_smallints(self._blknos[loc:]):
            blk = self.blocks[blkno]
            if count == len(blk.mgr_locs):
                blk.mgr_locs = blk.mgr_locs.add(1)
            else:
                new_mgr_locs = blk.mgr_locs.as_array.copy()
                new_mgr_locs[new_mgr_locs >= loc] += 1
                blk.mgr_locs = new_mgr_locs

        if loc == self._blklocs.shape[0]:
            # np.append is a lot faster, let's use it if we can.
            self._blklocs = np.append(self._blklocs, 0)
            self._blknos = np.append(self._blknos, len(self.blocks))
        else:
            self._blklocs = np.insert(self._blklocs, loc, 0)
            self._blknos = np.insert(self._blknos, loc, len(self.blocks))

        self.axes[0] = new_axis
        self.blocks += (block,)
        self._shape = None

        self._known_consolidated = False

        if len(self.blocks) > 100:
            self._consolidate_inplace()
def insert ( self , loc , item , value , allow_duplicates = False ) : if not allow_duplicates and item in self . items : raise ValueError ( 'cannot insert {}, already exists' . format ( item ) ) if not isinstance ( loc , int ) : raise TypeError ( "loc must be int" ) new_axis = self . items . insert ( loc , item ) block = make_block ( values = value , ndim = self . ndim , placement = slice ( loc , loc + 1 ) ) for blkno , count in _fast_count_smallints ( self . _blknos [ loc : ] ) : blk = self . blocks [ blkno ] if count == len ( blk . mgr_locs ) : blk . mgr_locs = blk . mgr_locs . add ( 1 ) else : new_mgr_locs = blk . mgr_locs . as_array . copy ( ) new_mgr_locs [ new_mgr_locs >= loc ] += 1 blk . mgr_locs = new_mgr_locs if loc == self . _blklocs . shape [ 0 ] : self . _blklocs = np . append ( self . _blklocs , 0 ) self . _blknos = np . append ( self . _blknos , len ( self . blocks ) ) else : self . _blklocs = np . insert ( self . _blklocs , loc , 0 ) self . _blknos = np . insert ( self . _blknos , loc , len ( self . blocks ) ) self . axes [ 0 ] = new_axis self . blocks += ( block , ) self . _shape = None self . _known_consolidated = False if len ( self . blocks ) > 100 : self . _consolidate_inplace ( )
Insert item at selected position.

        Parameters
        ----------
        loc : int
        item : hashable
        value : array_like
        allow_duplicates: bool
            If False, trying to insert non-unique item will raise