Returns
    -------
    topk : TopK filter expression
768658
def topk(arg, k, by=None):
    
    op = ops.TopK(arg, k, by=by)
    return op.to_expr()
750253
def _filter_from_dict(current: Dict[str, Any]) -> Dict[str, Any]:
    """"""
    filter_ = dict()

    for k, v in current.items():
        if isinstance(v, dict):
            for sub, v2 in _filter_from_dict(v).items():
                filter_[f'{k}.{sub}'] = v2
        else:
            filter_[k] = v

    return filter_
487873
def p_expression_binop(t):
    ''''''
    if t[2] == '+'  : t[0] = t[1] + t[3]
    elif t[2] == '-': t[0] = t[1] - t[3]
    elif t[2] == '*': t[0] = t[1] * t[3]
    elif t[2] == '/': t[0] = t[1] / t[3]
518014
def evaluate(self):
        

        try:
            self.condition = self.terms.prune(ConditionBinOp)
        except AttributeError:
            raise ValueError("cannot process expression [{expr}], [{slf}] "
                             "is not a valid condition".format(expr=self.expr,
                                                               slf=self))
        try:
            self.filter = self.terms.prune(FilterBinOp)
        except AttributeError:
            raise ValueError("cannot process expression [{expr}], [{slf}] "
                             "is not a valid filter".format(expr=self.expr,
                                                            slf=self))

        return self.condition, self.filter
648755
def top_matches(self, top):
        '''
        
        '''
        matches = DefaultOrderedDict(OrderedDict)
        # pylint: disable=cell-var-from-loop
        for saltenv, body in six.iteritems(top):
            if self.opts['saltenv']:
                if saltenv != self.opts['saltenv']:
                    continue
            for match, data in six.iteritems(body):
                def _filter_matches(_match, _data, _opts):
                    if isinstance(_data, six.string_types):
                        _data = [_data]
                    if self.matchers['confirm_top.confirm_top'](
                            _match,
                            _data,
                            _opts
                            ):
                        if saltenv not in matches:
                            matches[saltenv] = []
                        for item in _data:
                            if 'subfilter' in item:
                                _tmpdata = item.pop('subfilter')
                                for match, data in six.iteritems(_tmpdata):
                                    _filter_matches(match, data, _opts)
                            if isinstance(item, six.string_types):
                                matches[saltenv].append(item)
                            elif isinstance(item, dict):
                                env_key, inc_sls = item.popitem()
                                if env_key not in self.avail:
                                    continue
                                if env_key not in matches:
                                    matches[env_key] = []
                                matches[env_key].append(inc_sls)
                _filter_matches(match, data, self.opts['nodegroups'])
        ext_matches = self._master_tops()
        for saltenv in ext_matches:
            top_file_matches = matches.get(saltenv, [])
            if self.opts.get('master_tops_first'):
                first = ext_matches[saltenv]
                second = top_file_matches
            else:
                first = top_file_matches
                second = ext_matches[saltenv]
            matches[saltenv] = first + [x for x in second if x not in first]

        # pylint: enable=cell-var-from-loop
        return matches
1287003
function _getFilterIndex(filterSets, filter) {
        var index = -1;

        if (!filter || !filterSets.length) {
            return index;
        }

        return _.findIndex(filterSets, _.partial(_.isEqual, filter));
    }
314788
def _filter_list_to_conjunction_expression(filter_list):
    """"""
    if not isinstance(filter_list, list):
        raise AssertionError(u'Expected `list`, Received: {}.'.format(filter_list))
    if any((not isinstance(filter_block, Filter) for filter_block in filter_list)):
        raise AssertionError(u'Expected list of Filter objects. Received: {}'.format(filter_list))

    expression_list = [filter_block.predicate for filter_block in filter_list]
    return expression_list_to_conjunction(expression_list)
207207
def filterkeys(predicate, dict_):
    
    predicate = bool if predicate is None else ensure_callable(predicate)
    ensure_mapping(dict_)
    return dict_.__class__((k, v) for k, v in iteritems(dict_) if predicate(k))
336813
def _filter_by_support(in_file, data):
    
    rc_filter = ("FORMAT/SU < 4 || "
                 "(FORMAT/SR == 0 && FORMAT/SU < 15 && ABS(SVLEN)>50000) || "
                 "(FORMAT/SR == 0 && FORMAT/SU < 5 && ABS(SVLEN)<2000) || "
                 "(FORMAT/SR == 0 && FORMAT/SU < 15 && ABS(SVLEN)<300)")
    return vfilter.cutoff_w_expression(in_file, rc_filter, data, name="ReadCountSupport",
                                       limit_regions=None)
630732
def filter(self, s, method='exact', order=None):
        """"""
        return super(Gabor, self).filter(s, method='exact')
228054
def at_index(self, pos, predicate=None, index=None):
        
        return filter_index(self._index_dict[pos], predicate, index)
680088
def pre_filter(self):
        
        if len(self) == 1:
            return self[0].pre_filter()
        else:
            result = [x.pre_filter() for x in self if not isinstance(x, CompoundFilterBase)]
            result = [x for x in result if x]
            if result:
                if int(config.fast_query) == 1:
                    return result[0]  # using just one simple expression is safer
                else:
                    # TODO: make this purely value-based (is.nz=…)
                    return 'and={%s}' % ','.join(result)
        return ''
607421
def filter(cls, start_position="", max_results="", qb=None, **kwargs):
        
        return cls.where(build_where_clause(**kwargs),
                         start_position=start_position, max_results=max_results, qb=qb)
1249031
def _build_filters(_filters):
    
    root = utils.NestedDict({})
    for _filter in _filters:
        operation = None
        for operation, token in SPLIT_TOKENS:
            # split "some.key=value" into ["some.key", "value"]
            top_parts = _filter.split(token, 1)
            if len(top_parts) == 2:
                break
        else:
            raise exceptions.CLIAbort('Failed to find valid operation for: %s'
                                      % _filter)

        key, value = top_parts
        current = root
        # split "some.key" into ["some", "key"]
        parts = [part.strip() for part in key.split('.')]

        # Actually drill down and add the filter
        for part in parts[:-1]:
            current = current[part]

        if operation == 'eq':
            current[parts[-1]] = utils.query_filter(value.strip())
        elif operation == 'in':
            current[parts[-1]] = {
                'operation': 'in',
                'options': [{
                    'name': 'data',
                    'value': [p.strip() for p in value.split(',')],
                }],
            }

    return root.to_dict()
1168469
def p_expression(self, p):
        
        if len(p) == 2:
            left, op, right = p[1], None, None
        else:
            __, left, op, right = p
        p[0] = _filter.Expression(left, op, right)
119036
function gatherEntityFilters(context, expression) {
    let ii, len, bf, result, obj;

    let filter = expression[0];
    result = EntityFilter.create();

    switch (filter) {
        case ANY:
        case ANY_FILTER:
        case ALL:
        case ALL_FILTER:
        case NONE:
        case NONE_FILTER:
        case INCLUDE:
        case INCLUDE_FILTER:
            if (expression[1] === ROOT) {
                result.add(ROOT);
            } else {
                obj = context.valueOf(expression[1], true);

                if (!obj) {
                    if (filter == ALL_FILTER) {
                        result.add(ROOT);
                        return;
                    }
                    return null;
                }
                bf = context.componentsToBitfield(context, obj);

                // filter = expression[0];
                switch (filter) {
                    case ALL_FILTER:
                        filter = ALL;
                        break;
                    case ANY_FILTER:
                        filter = ANY;
                        break;
                    case NONE_FILTER:
                        filter = NONE;
                        break;
                    case INCLUDE_FILTER:
                        filter = INCLUDE;
                        break;
                    default:
                        break;
                }
                // console.log('CONVERTED TO BF', filter, bf.toString(), bf.toJSON() );
                result.add(filter, bf);
            }
            break;
        case AND:
            expression = expression.slice(1); // _.rest(expression);

            for (ii = 0, len = expression.length; ii < len; ii++) {
                obj = gatherEntityFilters(context, expression[ii]);
                if (!obj) {
                    return null;
                }
                result.filters = result.filters.concat(obj.filters);
            }
            break;
        default:
            return null;
    }

    return result;
}
681996
def scan(cls, filter_builder=None, **scan_filter):
        
        scan_kwargs = {'scan_filter': build_condition(scan_filter)}
        if filter_builder:
            cls._build_filter_expression(filter_builder, scan_kwargs)
        return ResultSet(cls, 'scan', scan_kwargs)