six.moves.map

Here are the examples of the python api six.moves.map taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

178 Examples 7

Example 1

Project: tensorpack Source File: common.py
Function: get_data
    def get_data(self):
        sums = np.cuemsum(self.sizes)
        idxs = np.arange(self.size())
        self.rng.shuffle(idxs)
        idxs = np.array(list(map(
            lambda x: np.searchsorted(sums, x, 'right'), idxs)))
        itrs = [k.get_data() for k in self.df_lists]
        assert idxs.max() == len(itrs) - 1, "{}!={}".format(idxs.max(), len(itrs)-1)
        for k in idxs:
            yield next(itrs[k])

Example 2

Project: tensorpack Source File: char-rnn.py
Function: init
    def __init__(self, input_file, size):
        self.seq_length = param.seq_len
        self._size = size
        self.rng = get_rng(self)

        logger.info("Loading corpus...")
        # preprocess data
        with open(input_file) as f:
            data = f.read()
        counter = Counter(data)
        char_cnt = sorted(counter.items(), key=operator.itemgetter(1), reverse=True)
        self.chars = [x[0] for x in char_cnt]
        self.vocab_size = len(self.chars)
        param.vocab_size = self.vocab_size
        self.lut = LookUpTable(self.chars)
        self.whole_seq = np.array(list(map(self.lut.get_idx, data)), dtype='int32')
        logger.info("Corpus loaded. Vocab size: {}".format(self.vocab_size))

Example 3

Project: formencode Source File: test_subclassing_old.py
Function: test_1_warnings
    def test_1_warnings(self):  # must run first
        with warnings.catch_warnings(record=True) as runtime_warnings:
            warnings.simplefilter('default')
            DeprecatedNotOneValidator().to_python('2')
        for output in runtime_warnings, not_one_warnings:
            output = '\n'.join(map(str, output))
            msg = '_to_python is deprecated; use _convert_to_python instead'
            self.assertTrue(msg in output, output or 'no warnings')

Example 4

Project: zerodb Source File: text_lucene.py
Function: search_all
    def _search_all(self, term):
        tokens = [t.lower() for t in _tokenizer_regex.findall(term)]
        glob_cond = lambda t: ('?' in t) or ('*' in t)
        glob_tokens = filter(glob_cond, tokens)
        word_tokens = filter(lambda t: not glob_cond(t), tokens)
        wids = set()
        wids.update(self._lexicon.termToWordIds(word_tokens))
        wids.update(itertools.chain(*map(self._lexicon.globToWordIds, glob_tokens)))
        wids = self._remove_oov_wids(wids)
        # XXX
        # We should have OrderedDict-like lazy objects
        # and we should have weightedIntersection and weightedUnion
        # working lazily in a for of zerodbext.catalog
        # This is just a workaround for simpler queries
        # XXX
        return imap(lambda x: x[0], mass_weightedUnion(self._search_wids(wids)))

Example 5

Project: python-mode Source File: imports.py
def _except_import_error(node):
    """
    Check if the try-except node has an ImportError handler.
    Return True if an ImportError handler was infered, False otherwise.
    """
    if not isinstance(node, astroid.TryExcept):
        return
    return any(map(is_import_error, node.handlers))

Example 6

Project: more-itertools Source File: recipes.py
Function: dot_product
def dotproduct(vec1, vec2):
    """Returns the dot product of the two iterables

        >>> dotproduct([10, 10], [20, 20])
        400

    """
    return sum(map(operator.mul, vec1, vec2))

Example 7

Project: django-cropduster Source File: __init__.py
    @cached_property
    def thumbs(self):
        thumb_ids = filter(None, self.request.GET.get('thumbs', '').split(','))
        try:
            thumb_ids = map(int, thumb_ids)
        except TypeError:
            thumbs = Thumb.objects.none()
        else:
            thumbs = Thumb.objects.filter(pk__in=thumb_ids)
        thumb_dict = dict([(t.name, t) for t in thumbs])
        ordered_thumbs = [thumb_dict.get(s.name, Thumb(name=s.name)) for s in self.sizes]
        return FakeQuerySet(ordered_thumbs, thumbs)

Example 8

Project: orderedmultidict Source File: test_orderedmultidict.py
    def test_str(self):
        for init in self.inits:
            omd = omdict(init)
            s = '{%s}' % ', '.join(
                map(lambda p: '%s: %s' % (p[0], p[1]), omd.allitems()))
            assert s == str(omd)

Example 9

Project: zipline Source File: argcheck.py
    def _defaults_match(self, arg):
        return any(map(Argument.ignore_default, [self, arg])) \
            or (self.default is Argument.any_default and
                arg.default is not Argument.no_default) \
            or (arg.default is Argument.any_default and
                self.default is not Argument.no_default) \
            or self.default == arg.default

Example 10

Project: fastqp Source File: plots.py
def qualdist(qualities, filename, fig_kw):
    fig = plt.figure(**fig_kw)
    ax = fig.add_subplot(111)
    fig.subplots_adjust(top=0.85)
    values = map(Counter, qualities)
    counts = Counter()
    for value in values:
        counts += value
    x, y = zip(*sorted(counts.items(), key=lambda x: x[0]))
    ax.bar([_ - 1 for _ in x], y, color=(0.1,0.6,0.8))
    ax.yaxis.grid(b=True, which='major', **{'color':'gray', 'linestyle':':'})
    ax.set_axisbelow(True)
    x1,x2,y1,y2 = ax.axis()
    ax.axis((x1,max(x), 0, y2))
    ax.set_title('Quality score cuemulative distribution')
    ax.set_xlabel('Phred score')
    ax.set_ylabel('Cumulative sum')
    add_figure_to_archive(fig, filename, 'quality_score_distribution.png')
    return np.median(tuple(itertools.chain(*([n] * m for n, m in counts.items()))))

Example 11

Project: taskw Source File: warrior.py
    def load_tasks(self, command='all'):
        def _load_tasks(filename):
            filename = os.path.join(self.config['data']['location'], filename)
            filename = os.path.expanduser(filename)
            with open(filename, 'r') as f:
                lines = f.readlines()

            return list(map(taskw.utils.decode_task, lines))

        return dict(
            (db, _load_tasks(DataFile.filename(db)))
            for db in Command.files(command)
        )

Example 12

Project: WAD Source File: clues.py
    def compile_clues(self):
        # compiling regular expressions
        for app in self.apps:
            regexps = {}
            for key in self.apps[app]:
                if key in ['script', 'html', 'url']:
                    regexps[key + "_re"] = list(six.moves.map(self.compile_clue, self.apps[app][key]))
                if key in ['meta', 'headers']:
                    regexps[key + "_re"] = {}
                    for entry in self.apps[app][key]:
                        regexps[key + "_re"][entry] = self.compile_clue(self.apps[app][key][entry])
            self.apps[app].update(regexps)

Example 13

Project: more-itertools Source File: recipes.py
Function: tabulate
def tabulate(function, start=0):
    """Return an iterator mapping the function over linear input.

    The start argument will be increased by 1 each time the iterator is called
    and fed into the function.

        >>> t = tabulate(lambda x: x**2, -3)
        >>> take(3, t)
        [9, 4, 1]

    """
    return map(function, count(start))

Example 14

Project: solvebio-python Source File: test_query.py
Function: test_paging
    def test_paging(self):
        page_size = 10
        num_pages = 3
        results = self.dataset.query(page_size=page_size)

        _results = []
        for (i, r) in enumerate(results):
            # fetch three pages and break
            if i / page_size == num_pages:
                break
            _results.append(r)

        self.assertEqual(len(_results), num_pages * page_size)
        self.assertEqual(
            len(set(map(str, _results))),
            num_pages * page_size
        )

Example 15

Project: formencode Source File: htmlgen.py
Function: str
    def str(self, arg, encoding=None):
        if isinstance(arg, six.string_types):
            if not isinstance(arg, str):
                arg = arg.encode(default_encoding)
            return arg
        elif arg is None:
            return ''
        elif isinstance(arg, (list, tuple)):
            return ''.join(map(self.str, arg))
        elif isinstance(arg, Element):
            return str(arg)
        else:
            arg = six.text_type(arg)
            if not isinstance(arg, str):  # Python 2
                arg = arg.encode(default_encoding)
            return arg

Example 16

Project: zipline Source File: core.py
    def __init__(self,
                 url='sqlite:///:memory:',
                 equities=_default_equities,
                 **frames):
        self._url = url
        self._eng = None
        if equities is self._default_equities:
            equities = make_simple_equity_info(
                list(map(ord, 'ABC')),
                pd.Timestamp(0),
                pd.Timestamp('2015'),
            )

        frames['equities'] = equities
        self._frames = frames
        self._eng = None  # set in enter and exit

Example 17

Project: orderedmultidict Source File: orderedmultidict.py
    def iterlists(self):
        '''
        Example:
          omd = omdict([(1,1), (1,11), (1,111), (2,2), (3,3)])
          omd.iterlists() -> [1,11,111] -> [2] -> [3]

        Returns: An iterator over the list comprised of the lists of values for
        each key.
        '''
        return map(lambda key: self.getlist(key), self)

Example 18

Project: pyswf Source File: export.py
    @classmethod
    def export_color_matrix_filter(cls, e, filter, matrix, svg_filter, attr_in=None, result='color-matrix'):
        attr_in = "SourceGraphic" if attr_in is None else attr_in
        fe_cxform = e.feColorMatrix()
        fe_cxform.set("in", attr_in)
        fe_cxform.set("type", "matrix")
        fe_cxform.set("values", " ".join(map(str, matrix)))
        fe_cxform.set("result", result)
        filter.append(fe_cxform)
        #print etree.tostring(filter, pretty_print=True)
        return result

Example 19

Project: pywb Source File: cdxsource.py
    def load_single_key(self, key):
        # ensure only url/surt is part of key
        key = key.split(b' ')[0]
        cdx_list = self.redis.zrange(self.key_prefix + key, 0, -1)

        # key is not part of list, so prepend to each line
        key += b' '
        cdx_list = list(map(lambda x: key + x, cdx_list))
        return cdx_list

Example 20

Project: crosscat Source File: LocalEngine.py
Function: init
    def __init__(self, seed=None):
        """Initialize a LocalEngine."""
        super(LocalEngine, self).__init__(seed=seed)
        self.mapper = lambda *args: list(six.moves.map(*args))
        self.do_initialize = _do_initialize_tuple
        self.do_analyze = _do_analyze_tuple
        self.do_insert = _do_insert_tuple
        return

Example 21

Project: PyEMMA Source File: patches.py
def _join_traj_data(traj_data, top_file):
    top = load_topology_cached(top_file)
    xyz = np.concatenate(tuple(map(itemgetter(0), traj_data)))

    traj = Trajectory(xyz, top)

    if all(t.unitcell_lengths is not None for t in traj_data):
        unitcell_lengths = np.concatenate(tuple(map(itemgetter(1), traj_data)))
        traj.unitcell_lengths = unitcell_lengths

    if all(t.box is not None for t in traj_data):
        boxes = np.concatenate(tuple(map(itemgetter(-1), traj_data)))
        traj.unitcell_vectors = boxes

    if all(t.unitcell_angles is not None for t in traj_data):
        angles = np.concatenate(tuple(map(itemgetter(2), traj_data)))
        traj.unitcell_angles = angles

    return traj

Example 22

Project: box-python-sdk Source File: test_logging_network.py
@pytest.fixture
def logger_call_count(logger_methods):

    def _logger_call_count():
        return sum(map(attrgetter('call_count'), logger_methods))

    return _logger_call_count

Example 23

Project: box-python-sdk Source File: test_group.py
@pytest.fixture()
def mock_membership_dict_stream():
    def gen_data(some_id):
        return {
            'type': 'group_membership',
            'id': "membership_id_{0}".format(some_id),
            'role': 'member',
            'user': {'type': 'user', 'id': "user_id_{0}".format(some_id)},
            'group': {'type': 'group', 'id': "group_id_{0}".format(some_id)},
        }

    return map(gen_data, count())

Example 24

Project: pgcontents Source File: db_utils.py
def to_dict_no_content(fields, row):
    """
    Convert a SQLAlchemy row that does not contain a 'content' field to a dict.

    If row is None, return None.

    Raises AssertionError if there is a field named 'content' in ``fields``.
    """
    assert(len(fields) == len(row))

    field_names = list(map(_get_name, fields))
    assert 'content' not in field_names, "Unexpected content field."

    return dict(zip(field_names, row))

Example 25

Project: nzbToMedia Source File: __init__.py
Function: join
def join(*paths):
	r"""
	Wrapper around os.path.join that works with Windows drive letters.

	>>> join('d:\\foo', '\\bar')
	'd:\\bar'
	"""
	paths_with_drives = map(os.path.splitdrive, paths)
	drives, paths = zip(*paths_with_drives)
	# the drive we care about is the last one in the list
	drive = next(filter(None, reversed(drives)), '')
	return os.path.join(drive, os.path.join(*paths))

Example 26

Project: attention-lvcsr Source File: sqlite.py
Function: iter
    def __iter__(self):
        return map(itemgetter(0), self.log.conn.execute(
            ANCESTORS_QUERY + "SELECT key FROM entries "
            "WHERE uuid IN ancestors AND time = ?",
            (self.log.h_uuid, self.time,)
        ))

Example 27

Project: abstract_rendering Source File: glyphset.py
Function: call
    def __call__(self, vals):
        if not self.colMajor:
            shapes = [list(map(lambda f: f(val), self.fns)) for val in vals]
        else:
            shapes = [list(map(lambda f: f(val), self.fns)) for val in zip(*vals)]

        return shapes

Example 28

Project: elasticsearch-dsl-py Source File: field.py
Function: deserialize
    def _deserialize(self, data):
        if data is None:
            return None
        # don't wrap already wrapped data
        if isinstance(data, self._doc_class):
            return data

        if isinstance(data, (list, AttrList)):
            data[:] = list(map(self._deserialize, data))
            return data

        if isinstance(data, AttrDict):
            data = data._d_

        return self._wrap(data)

Example 29

Project: django-adminactions Source File: massupdate.py
@register.simple_tag
def fields_values(d, k):
    """
    >>> data = {'name1': ['value1.1', 'value1.2'], 'name2': ['value2.1', 'value2.2'], }
    >>> print(fields_values(data, 'name1'))
    value1.1,value1.2
    """
    values = d.get(k, [])
    return ",".join(map(str, values))

Example 30

Project: more-itertools Source File: recipes.py
Function: quantify
def quantify(iterable, pred=bool):
    """Return the how many times the predicate is true

        >>> quantify([True, False, True])
        2

    """
    return sum(map(pred, iterable))

Example 31

Project: zipline Source File: test_events.py
    def test_ComposedRule(self):
        minute_groups = minutes_for_days(self.cal)
        rule1 = Always()
        rule2 = Never()

        for minute in minute_groups:
            composed = rule1 & rule2
            should_trigger = composed.should_trigger
            self.assertIsInstance(composed, ComposedRule)
            self.assertIs(composed.first, rule1)
            self.assertIs(composed.second, rule2)
            self.assertFalse(any(map(should_trigger, minute)))

Example 32

Project: more-itertools Source File: recipes.py
Function: unique_justseen
def unique_justseen(iterable, key=None):
    """Yields elements in order, ignoring serial duplicates

        >>> list(unique_justseen('AAAABBBCCDAABBB'))
        ['A', 'B', 'C', 'D', 'A', 'B']
        >>> list(unique_justseen('ABBCcAD', str.lower))
        ['A', 'B', 'C', 'A', 'D']

    """
    return map(next, map(operator.itemgetter(1), groupby(iterable, key)))

Example 33

Project: solvebio-python Source File: test_query.py
    def test_paging_with_limit(self):
        page_size = 10
        num_pages = 3
        limit = num_pages * page_size - 1
        results = self.dataset.query(limit=limit, page_size=page_size)

        _results = []
        for (i, r) in enumerate(results):
            _results.append(r)

        self.assertEqual(len(_results), limit)
        self.assertEqual(
            len(set(map(str, _results))),
            limit
        )

Example 34

Project: formencode Source File: test_subclassing_old.py
Function: test_1_warnings
    def test_1_warnings(self):
        deprecated = (
            ('_to_python', '_convert_to_python'),
            ('_from_python', '_convert_from_python'),
            ('validate_other', '_validate_other'),
            ('validate_python', '_validate_python'))
        output = '\n'.join(map(str, custom_warnings))
        for old, new in deprecated:
            msg = '%s is deprecated; use %s instead' % (old, new)
            self.assertTrue(msg in output, output or 'no warnings')

Example 35

Project: django_any_backend Source File: testcases.py
    def assertQuerysetsEqual(self, qs1, qs2, transform=repr, ordered=True, msg=None):
        self.assertIsNotNone(qs1, msg=msg)
        self.assertIsNotNone(qs2, msg=msg)
        with self.settings(**self.override_settings):
            qs1_items = six.moves.map(transform, qs1)
            qs2_items = six.moves.map(transform, qs2)
        if not ordered:
            return self.assertEqual(Counter(qs1_items), Counter(qs2_items), msg=msg)
        qs1_values = list(qs1_items)
        qs2_values = list(qs2_items)
        self.assertEqual(qs1_values, qs2_values, msg=msg)

Example 36

Project: formencode Source File: test_subclassing_old.py
Function: test_1_warnings
    def test_1_warnings(self):  # must run first
        with warnings.catch_warnings(record=True) as runtime_warnings:
            warnings.simplefilter('default')
            self.validator.to_python('3')
        for output in runtime_warnings, all_and_not_one_warnings:
            output = '\n'.join(map(str, output))
            msg = 'attempt_convert is deprecated; use _attempt_convert instead'
            self.assertTrue(msg in output, output or 'no warnings')

Example 37

Project: pyswf Source File: export.py
    def export_color_transform(self, cxform, svg_filter, result='color-xform'):
        fe_cxform = self._e.feColorMatrix()
        fe_cxform.set("in", "SourceGraphic")
        fe_cxform.set("type", "matrix")
        fe_cxform.set("values", " ".join(map(str, cxform.matrix)))
        fe_cxform.set("result", "cxform")

        fe_composite = self._e.feComposite(operator="in")
        fe_composite.set("in2", "SourceGraphic")
        fe_composite.set("result", result)

        svg_filter.append(fe_cxform)
        svg_filter.append(fe_composite)
        return result

Example 38

Project: orderedmultidict Source File: orderedmultidict.py
    def iterlistitems(self):
        """
        Example:
          omd = omdict([(1,1), (1,11), (1,111), (2,2), (3,3)])
          omd.iterlistitems() -> (1,[1,11,111]) -> (2,[2]) -> (3,[3])

        Returns: An iterator over the list of key:valuelist items.
        """
        return map(lambda key: (key, self.getlist(key)), self)

Example 39

Project: zipline Source File: core.py
def gen_calendars(start, stop, critical_dates):
    """
    Generate calendars to use as inputs.
    """
    all_dates = pd.date_range(start, stop, tz='utc')
    for to_drop in map(list, powerset(critical_dates)):
        # Have to yield tuples.
        yield (all_dates.drop(to_drop),)

    # Also test with the trading calendar.
    trading_days = get_calendar("NYSE").all_days
    yield (trading_days[trading_days.slice_indexer(start, stop)],)

Example 40

Project: pywb Source File: cdxops.py
def create_merged_cdx_gen(sources, query):
    """
    create a generator which loads and merges cdx streams
    ensures cdxs are lazy loaded
    """
    # Optimize: no need to merge if just one input
    if len(sources) == 1:
        cdx_iter = sources[0].load_cdx(query)
    else:
        source_iters = map(lambda src: src.load_cdx(query), sources)
        cdx_iter = merge(*(source_iters))

    for cdx in cdx_iter:
        yield cdx

Example 41

Project: zhang-shasha Source File: test_metricspace.py
Function: product
def product(*args, **kwds):
    # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
    # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
    pools = list(map(tuple, args)) * kwds.get('repeat', 1)
    result = [[]]
    for pool in pools:
        result = [x+[y] for x in result for y in pool]
    for prod in result:
        yield tuple(prod)

Example 42

Project: pywb Source File: timeutils.py
def iso_date_to_datetime(string):
    """
    >>> iso_date_to_datetime('2013-12-26T10:11:12Z')
    datetime.datetime(2013, 12, 26, 10, 11, 12)

    >>> iso_date_to_datetime('2013-12-26T10:11:12Z')
    datetime.datetime(2013, 12, 26, 10, 11, 12)
     """

    nums = DATE_TIMESPLIT.split(string)
    if nums[-1] == '':
        nums = nums[:-1]

    the_datetime = datetime.datetime(*map(int, nums))
    return the_datetime

Example 43

Project: python-librato Source File: __init__.py
Function: delete
    def delete(self, names):
        if isinstance(names, six.string_types):
            names = self.sanitize(names)
        else:
            names = list(map(self.sanitize, names))
        path = "metrics/%s" % names
        payload = {}
        if not isinstance(names, string_types):
            payload = {'names': names}
            path = "metrics"
        return self._mexe(path, method="DELETE", query_props=payload)

Example 44

Project: box-python-sdk Source File: enum.py
Function: contains
    def __contains__(cls, member):
        if super(ExtendableEnumMeta, cls).__contains__(member):
            return True

        def in_(subclass):
            return member in subclass

        return any(map(in_, cls.__subclasses__()))

Example 45

Project: zipline Source File: argcheck.py
Function: str
    def __str__(self):
        missing_args = list(map(str, self.missing_args))
        return '%s is missing argument%s: %s' % (
            self.format_callable(),
            's' if len(missing_args) > 1 else '',
            ', '.join(missing_args),
        )

Example 46

Project: CouchPotatoServer Source File: scanner.py
Function: get_codec
    def getCodec(self, filename, codecs):
        codecs = map(re.escape, codecs)
        try:
            codec = re.search('[^A-Z0-9](?P<codec>' + '|'.join(codecs) + ')[^A-Z0-9]', filename, re.I)
            return (codec and codec.group('codec')) or ''
        except:
            return ''

Example 47

Project: tensorpack Source File: visualqa.py
Function: init
    def __init__(self, question_file, annotation_file):
        with timed_operation('Reading VQA JSON file'):
            qobj, aobj = list(map(read_json, [question_file, annotation_file]))
            self.task_type = qobj['task_type']
            self.questions = qobj['questions']
            self._size = len(self.questions)

            self.anno = aobj['annotations']
            assert len(self.anno) == len(self.questions), \
                "{}!={}".format(len(self.anno), len(self.questions))
            self._clean()

Example 48

Project: pgcontents Source File: db_utils.py
def to_dict_with_content(fields, row, decrypt_func):
    """
    Convert a SQLAlchemy row that contains a 'content' field to a dict.

    ``decrypt_func`` will be applied to the ``content`` field of the row.

    If row is None, return None.

    Raises AssertionError if there is no field named 'content' in ``fields``.
    """
    assert(len(fields) == len(row))

    field_names = list(map(_get_name, fields))
    assert 'content' in field_names, "Missing content field."

    result = dict(zip(field_names, row))
    result['content'] = decrypt_func(result['content'])
    return result

Example 49

Project: kerncraft Source File: kernel.py
def find_array_references(ast):
    '''returns list of array references in AST'''
    if type(ast) is c_ast.ArrayRef:
        return [ast]
    elif type(ast) is list:
        return list(map(find_array_references, ast))
    elif ast is None:
        return []
    else:
        return reduce(operator.add, [find_array_references(o[1]) for o in ast.children()], [])

Example 50

Project: debsources Source File: mainlib.py
def conf_warnings(conf):
    """check configuration `conf` and log warnings about non standard settings
    if needed

    """
    if conf['dry_run']:
        logging.warn('note: DRY RUN mode is enabled')
    if conf['backends'] != set(DEFAULT_CONFIG['infra']['backends'].split()):
        logging.warn('only using backends: %s' % list(conf['backends']))
    if conf['stages'] != updater.UPDATE_STAGES:
        logging.warn('only doing stages: %s' %
                     list(map(updater.pp_stage, conf['stages'])))
    if conf['force_triggers']:
        logging.warn('forcing triggers: %s' % conf['force_triggers'])
See More Examples - Go to Next Page
Page 1 Selected Page 2 Page 3 Page 4