当前位置: 首页>>代码示例>>Python>>正文


Python toolz.first方法代码示例

本文整理汇总了Python中toolz.first方法的典型用法代码示例。如果您正苦于以下问题:Python toolz.first方法的具体用法?Python toolz.first怎么用?Python toolz.first使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在toolz的用法示例。


在下文中一共展示了toolz.first方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _write_df_to_table

# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import first [as 别名]
def _write_df_to_table(
        self,
        tbl,
        df,
        txn,
        chunk_size,
        idx=True,
        idx_label=None,
    ):
        df.to_sql(
            tbl.name,
            txn.connection,
            index=idx,
            index_label=(
                idx_label
                if idx_label is not None else
                first(tbl.primary_key.columns).name
            ),
            if_exists='append',
            chunksize=chunk_size,
        ) 
开发者ID:enigmampc,项目名称:catalyst,代码行数:23,代码来源:asset_writer.py

示例2: first_repeated

# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import first [as 别名]
def first_repeated(key: Func, seq: Seq):
    """
    Return the index and value of first repeated element in sequence.

    Raises a ValueError if no repeated element is found.

    Examples:
        >>> first_repeated(None, [1, 2, 3, 1])
        (3, 1)
    """

    key = to_callable(key)
    seen = set()
    add = seen.add
    for i, x in enumerate(seq):
        tag = key(x)
        if tag in seen:
            return i, x
        add(tag)
    raise ValueError("no repeated element in sequence") 
开发者ID:fabiommendes,项目名称:sidekick,代码行数:22,代码来源:experimental.py

示例3: peek

# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import first [as 别名]
def peek(seq: Seq, default=NOT_GIVEN) -> (object, Seq):
    """
    Same as peek_with(first).

    Peek first element of sequence and return (first, seq).

    >>> fst, seq = peek(range(5))
    >>> fst, list(seq)
    (0, [0, 1, 2, 3, 4])
    """
    try:
        x, seq = uncons(seq)
    except ValueError:
        if default is NOT_GIVEN:
            raise
        return default, iter(())
    return x, toolz.cons(x, seq) 
开发者ID:fabiommendes,项目名称:sidekick,代码行数:19,代码来源:experimental.py

示例4: detect_fastq_annotations

# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import first [as 别名]
def detect_fastq_annotations(fastq_file):
    """
    detects annotations preesent in a FASTQ file by examining the first read
    """
    annotations = set()
    queryread = tz.first(read_fastq(fastq_file))
    for k, v in BARCODEINFO.items():
        if v.readprefix in queryread:
            annotations.add(k)
    return annotations 
开发者ID:vals,项目名称:umis,代码行数:12,代码来源:umis.py

示例5: subset_bamfile

# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import first [as 别名]
def subset_bamfile(sam, barcodes):
    """
    Subset a SAM/BAM file, keeping only alignments from given
    cellular barcodes
    """
    from pysam import AlignmentFile

    start_time = time.time()

    sam_file = open_bamfile(sam)
    out_file = AlignmentFile("-", "wh", template=sam_file)
    track = sam_file.fetch(until_eof=True)

    # peek at first alignment to determine the annotations
    queryalignment = track.next()
    annotations = detect_alignment_annotations(queryalignment)
    track = itertools.chain([queryalignment], track)

    re_string = construct_transformed_regex(annotations)
    parser_re = re.compile(re_string)
    barcodes = set(barcode.strip() for barcode in barcodes)

    for count, aln in enumerate(track, start=1):
        if count and not count % 1000000:
            logger.info("Processed %d alignments." % count)

        match = parser_re.match(aln.qname)
        tags = aln.tags

        if "cellular" in annotations:
            cb = match.group('CB')
            if cb in barcodes:
                out_file.write(aln) 
开发者ID:vals,项目名称:umis,代码行数:35,代码来源:umis.py

示例6: create_table

# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import first [as 别名]
def create_table(self, table_name, obj=None, schema=None):
        """Create a table."""
        if obj is None and schema is None:
            raise com.IbisError('Must pass expr or schema')

        if obj is not None:
            df = pd.DataFrame(obj)
        else:
            dtypes = ibis_schema_to_pandas(schema)
            df = schema.apply_to(
                pd.DataFrame(columns=list(map(toolz.first, dtypes)))
            )

        self.dictionary[table_name] = df 
开发者ID:ibis-project,项目名称:ibis,代码行数:16,代码来源:client.py

示例7: remap_overlapping_column_names

# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import first [as 别名]
def remap_overlapping_column_names(table_op, root_table, data_columns):
    """Return an ``OrderedDict`` mapping possibly suffixed column names to
    column names without suffixes.

    Parameters
    ----------
    table_op : TableNode
        The ``TableNode`` we're selecting from.
    root_table : TableNode
        The root table of the expression we're selecting from.
    data_columns : set or frozenset
        The available columns to select from

    Returns
    -------
    mapping : OrderedDict[str, str]
        A map from possibly-suffixed column names to column names without
        suffixes.
    """
    if not isinstance(table_op, ops.Join):
        return None

    left_root, right_root = ops.distinct_roots(table_op.left, table_op.right)
    suffixes = {
        left_root: constants.LEFT_JOIN_SUFFIX,
        right_root: constants.RIGHT_JOIN_SUFFIX,
    }
    column_names = [
        ({name, name + suffixes[root_table]} & data_columns, name)
        for name in root_table.schema.names
    ]
    mapping = OrderedDict(
        (first(col_name), final_name)
        for col_name, final_name in column_names
        if col_name
    )
    return mapping 
开发者ID:ibis-project,项目名称:ibis,代码行数:39,代码来源:selection.py

示例8: haystack_to_series_of_lists

# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import first [as 别名]
def haystack_to_series_of_lists(haystack, index=None):
    if index is None:
        index = toolz.first(
            piece.index for piece in haystack if hasattr(piece, 'index')
        )
    pieces = reduce(
        operator.add,
        (
            pd.Series(getattr(piece, 'values', piece), index=index).map(
                ibis.util.promote_list
            )
            for piece in haystack
        ),
    )
    return pieces 
开发者ID:ibis-project,项目名称:ibis,代码行数:17,代码来源:strings.py

示例9: execute_string_group_by_find_in_set

# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import first [as 别名]
def execute_string_group_by_find_in_set(op, needle, haystack, **kwargs):
    # `list` could contain series, series groupbys, or scalars
    # mixing series and series groupbys is not allowed
    series_in_haystack = [
        type(piece)
        for piece in haystack
        if isinstance(piece, (pd.Series, SeriesGroupBy))
    ]

    if not series_in_haystack:
        return ibis.util.safe_index(haystack, needle)

    try:
        (collection_type,) = frozenset(map(type, series_in_haystack))
    except ValueError:
        raise ValueError('Mixing Series and SeriesGroupBy is not allowed')

    pieces = haystack_to_series_of_lists(
        [getattr(piece, 'obj', piece) for piece in haystack]
    )

    result = pieces.map(toolz.flip(ibis.util.safe_index)(needle))
    if issubclass(collection_type, pd.Series):
        return result

    assert issubclass(collection_type, SeriesGroupBy)

    return result.groupby(
        toolz.first(
            piece.grouper.groupings
            for piece in haystack
            if hasattr(piece, 'grouper')
        )
    ) 
开发者ID:ibis-project,项目名称:ibis,代码行数:36,代码来源:strings.py

示例10: __init__

# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import first [as 别名]
def __init__(
        self, table, by, having=None, order_by=None, window=None, **expressions
    ):
        self.table = table
        self.by = util.promote_list(by if by is not None else []) + [
            _get_group_by_key(table, v).name(k)
            for k, v in sorted(expressions.items(), key=toolz.first)
        ]
        self._order_by = order_by or []
        self._having = having or []
        self._window = window 
开发者ID:ibis-project,项目名称:ibis,代码行数:13,代码来源:groupby.py

示例11: main_loop

# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import first [as 别名]
def main_loop(self):
        if not hasattr(self, '_main_loop'):
            raise ValueError("main loop must be assigned to extension first")
        return self._main_loop 
开发者ID:rizar,项目名称:attention-lvcsr,代码行数:6,代码来源:__init__.py

示例12: _print_attributes

# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import first [as 别名]
def _print_attributes(self, attribute_tuples):
        for attr, value in sorted(attribute_tuples.items(), key=first):
            if not self._attribute_filter(attr):
                print("\t", "{}:".format(attr), value) 
开发者ID:rizar,项目名称:attention-lvcsr,代码行数:6,代码来源:__init__.py

示例13: indexed_map

# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import first [as 别名]
def indexed_map(func: Func, *seqs: Seq, start=0) -> Seq:
    """
    Like map, but pass the index of each element as the first argument to
    func.

    Examples:
        >>> ''.join(indexed_map((X * Y), 'hello', start=1))
        'heelllllllooooo'

    See Also:
        map
    """
    return _map(func, itertools.count(start), *seqs) 
开发者ID:fabiommendes,项目名称:sidekick,代码行数:15,代码来源:experimental.py

示例14: index

# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import first [as 别名]
def index(x, seq):
    try:
        return toolz.first(i for i, y in enumerate(seq) if x == y)
    except ValueError:
        raise IndexError("element not found in sequence") 
开发者ID:fabiommendes,项目名称:sidekick,代码行数:7,代码来源:experimental.py

示例15: _adapt

# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import first [as 别名]
def _adapt(self, info):
        # First, have an adaptive algorithm
        if self.n_initial_parameters == "grid":
            start = len(ParameterGrid(self.parameters))
        else:
            start = self.n_initial_parameters

        def inverse(time):
            """ Decrease target number of models inversely with time """
            return int(start / (1 + time) ** self.decay_rate)

        example = toolz.first(info.values())
        time_step = example[-1]["partial_fit_calls"]

        current_time_step = time_step + 1
        next_time_step = current_time_step

        if inverse(current_time_step) == 0:
            # we'll never get out of here
            next_time_step = 1

        while inverse(current_time_step) == inverse(next_time_step) and (
            self.decay_rate
            and not self.patience
            or next_time_step - current_time_step < self.fits_per_score
        ):
            next_time_step += 1

        target = max(1, inverse(next_time_step))
        best = toolz.topk(target, info, key=lambda k: info[k][-1]["score"])

        if len(best) == 1:
            [best] = best
            return {best: 0}
        steps = next_time_step - current_time_step
        instructions = {b: steps for b in best}
        return instructions 
开发者ID:dask,项目名称:dask-ml,代码行数:39,代码来源:_incremental.py


注:本文中的toolz.first方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。