packages/vaex-core/vaex/dataframe.py
def mode(self, expression, binby=[], limits=None, shape=256, mode_shape=64, mode_limits=None, progressbar=False, selection=None):
        """Calculate/estimate the mode."""
        if len(binby) == 0:
            raise ValueError("only supported with binby argument given")
        else:
            # todo, fix progressbar into two...
            try:
                len(shape)
                shape = tuple(shape)
            except:
                shape = len(binby) * (shape,)
            shape = (mode_shape,) + shape
            subspace = self(*(list(binby) + [expression]))
            if selection:
                subspace = subspace.selected()

            limits = self.limits(list(binby), limits)
            mode_limits = self.limits([expression], mode_limits)
            limits = list(limits) + list(mode_limits)
            counts = subspace.histogram(limits=limits, size=shape, progressbar=progressbar)

            indices = np.argmax(counts, axis=0)
            pmin, pmax = limits[-1]
            centers = np.linspace(pmin, pmax, mode_shape + 1)[:-1]  # ignore last bin
            centers += (centers[1] - centers[0]) / 2  # and move half a bin to the right

            modes = centers[indices]
            ok = counts.sum(axis=0) > 0
            modes[~ok] = np.nan
            return modes
def mode(self, expression, binby=[], limits=None, shape=256, mode_shape=64, mode_limits=None, progressbar=False, selection=None):
        """Calculate/estimate the mode."""
        if len(binby) == 0:
            raise ValueError("only supported with binby argument given")
        else:
            # todo, fix progressbar into two...
            try:
                len(shape)
                shape = tuple(shape)
            except:
                shape = len(binby) * (shape,)
            shape = (mode_shape,) + shape
            subspace = self(*(list(binby) + [expression]))
            if selection:
                subspace = subspace.selected()

            limits = self.limits(list(binby), limits)
            mode_limits = self.limits([expression], mode_limits)
            limits = list(limits) + list(mode_limits)
            counts = subspace.histogram(limits=limits, size=shape, progressbar=progressbar)

            indices = np.argmax(counts, axis=0)
            pmin, pmax = limits[-1]
            centers = np.linspace(pmin, pmax, mode_shape + 1)[:-1]  # ignore last bin
            centers += (centers[1] - centers[0]) / 2  # and move half a bin to the right

            modes = centers[indices]
            ok = counts.sum(axis=0) > 0
            modes[~ok] = np.nan
            return modes
def mode ( self , expression , binby = [ ] , limits = None , shape = 256 , mode_shape = 64 , mode_limits = None , progressbar = False , selection = None ) : if len ( binby ) == 0 : raise ValueError ( "only supported with binby argument given" ) else : # todo, fix progressbar into two... try : len ( shape ) shape = tuple ( shape ) except : shape = len ( binby ) * ( shape , ) shape = ( mode_shape , ) + shape subspace = self ( * ( list ( binby ) + [ expression ] ) ) if selection : subspace = subspace . selected ( ) limits = self . limits ( list ( binby ) , limits ) mode_limits = self . limits ( [ expression ] , mode_limits ) limits = list ( limits ) + list ( mode_limits ) counts = subspace . histogram ( limits = limits , size = shape , progressbar = progressbar ) indices = np . argmax ( counts , axis = 0 ) pmin , pmax = limits [ - 1 ] centers = np . linspace ( pmin , pmax , mode_shape + 1 ) [ : - 1 ] # ignore last bin centers += ( centers [ 1 ] - centers [ 0 ] ) / 2 # and move half a bin to the right modes = centers [ indices ] ok = counts . sum ( axis = 0 ) > 0 modes [ ~ ok ] = np . nan return modes
Calculate/estimate the mode.
Calculate / estimate the mode .