Filter the occurrences with respect to the selected relational operators
341056
def _filter_occurrences(count, relat_op):
    """"""
    # Filter the occurrences equal (or not equal) to a given value
    if "eq" in relat_op:
        count = dfilter(lambda x: x == relat_op["eq"], count)
    elif "ne" in relat_op:
        count = dfilter(lambda x: x != relat_op["ne"], count)

    # Filter the occurrences lower (or equal) than a given value
    if "lt" in relat_op:
        count = dfilter(lambda x: x < relat_op["lt"], count)
    elif "le" in relat_op:
        count = dfilter(lambda x: x <= relat_op["le"], count)

    # Filter the occurrences greater (or equal) than a given value
    if "gt" in relat_op:
        count = dfilter(lambda x: x > relat_op["gt"], count)
    elif "ge" in relat_op:
        count = dfilter(lambda x: x >= relat_op["ge"], count)
    return count
588531
def _filter(self):
        
        pattern = u"[\s+\.\!\-\/_,$%^*(+\"\']+|[+——！】【，。？?:、：~@#￥%……&*“”（）]+"
        self.m = re.sub(pattern, "", self.m)
1132735
def filter(self, table, users, filter_string):
        """"""
        q = filter_string.lower()
        return [user for user in users
                if (q in user.name.lower() or
                    q in (getattr(user, 'email', None) or '').lower())]
1000532
def dfilter(fn, record):
    
    return dict([(k, v) for k, v in record.items() if fn(v)])
891371
function filterInPlace (arr, pred) {
  var idx = 0;
  for (var ii = 0; ii < arr.length; ++ii) {
    if (pred(arr[ii])) {
      arr[idx] = arr[ii];
      ++idx;
    }
  }
  arr.length = idx;
}
406453
def selections(self):
        ""
        for key, value in self.pairs:
            if '__' in key:
                column, lookup = key.rsplit('__', 1)
            else:
                column = key
                lookup = 'exact'
            yield column, lookup, value
17530
def filter(self, *predicates):
        
        predicates = self._get_fields(predicates)

        predicate = reduce(operator.and_, predicates)
        return FilterCollectionExpr(self, predicate, _schema=self._schema)
1154833
def join_filter(sep, seq, pred=bool):
    
    return sep.join([text_type(i) for i in seq if pred(i)])
228589
def _filter_seqs(fn):
    """"""
    out_file = op.splitext(fn)[0] + "_unique.fa"
    idx = 0
    if not file_exists(out_file):
        with open(out_file, 'w') as out_handle:
            with open(fn) as in_handle:
                for line in in_handle:
                    if line.startswith("@") or line.startswith(">"):
                        fixed_name = _make_unique(line.strip(), idx)
                        seq = in_handle.next().strip()
                        counts = _get_freq(fixed_name)
                        if len(seq) < 26 and (counts > 1 or counts == 0):
                            idx += 1
                            print(fixed_name, file=out_handle, end="\n")
                            print(seq, file=out_handle, end="\n")
                        if line.startswith("@"):
                            in_handle.next()
                            in_handle.next()
    return out_file
1312471
def get_relation_cols(self):
        
        retlst = []
        for flt, value in zip(self.filters, self.values):
            if isinstance(flt, FilterRelation) and value:
                retlst.append(flt.column_name)
        return retlst
1284745
def related_to(self, instance):
        """"""
        return self.filter(table_name=instance.table_name, record_id=instance.record_id)
1024584
def _finish_filter(self, lst, key, include_self, exclusive, biggest_first):
        """"""
        key = self._actual_key(key)
        locations = [x[0] for x in lst]

        if not include_self and key in locations:
            lst.pop(locations.index(key))

        lst.sort(key=lambda x: x[1], reverse=biggest_first)
        lst = [x for x, y in lst]

        # RoW in both key and lst, but not defined; only RoW remains if exclusive
        if key == 'RoW' and 'RoW' not in self and exclusive:
            return ['RoW'] if 'RoW' in lst else []
        elif exclusive:
            removed, remaining = set(), []
            while lst:
                current = lst.pop(0)
                faces = self[current]
                if not faces.intersection(removed):
                    removed.update(faces)
                    remaining.append(current)
            lst = remaining

        # If RoW not resolved, make it the smallest
        if 'RoW' not in self and 'RoW' in lst:
            lst[-1 if biggest_first else 0] = lst.pop(lst.index('RoW'))

        return lst
333168
def with_upcoming_occurrences(self):
        
        return self.filter(
            Q(is_drop_in=False, occurrences__start__gte=djtz.now) |
            Q(Q(is_drop_in=True) | Q(occurrences__is_all_day=True), occurrences__end__gt=djtz.now)
        )
420039
def filter(*conditions)
      latest = !conditions.select {|item| item === true }.empty?
      filters = translate_conditions(conditions)
      items = list(latest)
      unless filters.empty?
        items = items.select do |item|
          !filters.select {|filter| match_filter(filter, item) }.empty?
        end

      end
      items
    end
1051038
function () {
            return [
                        __.filter (123, _.constant (456)).assert (456),
                        __.filter (['foo', 456], _.isString).assert (['foo']),
                        __.filter (['foo', 456], __.constant ('baz')).assert (['baz', 'baz']),
                        __.filter ({ foo: 123, bar: '456' }, _.isNumber).assert ({ foo: 123 })
                    ] }
788156
def parse_filter_tokens(expression, tokens)     #:nodoc:
      operators = {
        '==' => 2,
        '='  => 2,
        '=~' => 2,
        'eq' => 2,

        '!=' => 5,
        '!~' => 5,
        'ne' => 5,
        '<>' => 5,

        '<'  => 1,
        '<=' => 3,
        '>'  => 4,
        '>=' => 6,
      }

      operator = operators[tokens[1]]
      token    = tokens[2]

      # Special handling of "Top" filter expressions.
      if tokens[0] =~ /^top|bottom$/i
        value = tokens[1]
        if (value =~ /\D/ or value.to_i < 1 or value.to_i > 500)
          raise "The value '#{value}' in expression '#{expression}' " +
          "must be in the range 1 to 500"
        end
        token.downcase!
        if (token != 'items' and token != '%')
          raise "The type '#{token}' in expression '#{expression}' " +
          "must be either 'items' or '%'"
        end

        if (tokens[0] =~ /^top$/i)
          operator = 30
        else
          operator = 32
        end

        if (tokens[2] == '%')
          operator += 1
        end

        token    = value
      end

      if (not operator and tokens[0])
        raise "Token '#{tokens[1]}' is not a valid operator " +
        "in filter expression '#{expression}'"
      end

      # Special handling for Blanks/NonBlanks.
      if (token =~ /^blanks|nonblanks$/i)
        # Only allow Equals or NotEqual in this context.
        if (operator != 2 and operator != 5)
          raise "The operator '#{tokens[1]}' in expression '#{expression}' " +
          "is not valid in relation to Blanks/NonBlanks'"
        end

        token.downcase!

        # The operator should always be 2 (=) to flag a "simple" equality in
        # the binary record. Therefore we convert <> to =.
        if token == 'blanks'
          if operator == 5
            token = ' '
          end
        else
          if operator == 5
            operator = 2
            token    = 'blanks'
          else
            operator = 5
            token    = ' '
          end
        end
      end

      # if the string token contains an Excel match character then change the
      # operator type to indicate a non "simple" equality.
      if (operator == 2 and token =~ /[*?]/)
        operator = 22
      end

      [operator, token]
    end
192016
def filter_select_columns_intensity(df, prefix, columns):
    
    # Note: I use %s.+ (not %s.*) so it forces a match with the prefix string, ONLY if it is followed by something.
    return df.filter(regex='^(%s.+|%s)$' % (prefix, '|'.join(columns)) )