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


Python toolz.valfilter方法代码示例

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


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

示例1: prepare

# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import valfilter [as 别名]
def prepare(query, connection=None, external=None):
    connection = merge(_default, connection or {})
    database = escape(connection['database'])
    query = query.format(db=database)
    params = {'database': connection['database'],
              'query': query,
              'user': connection['user'],
              'password': connection['password']}
    params = valfilter(lambda x: x, params)

    files = {}
    external = external or {}
    for name, (structure, serialized) in external.items():
        params['{}_format'.format(name)] = 'CSV'
        params['{}_structure'.format(name)] = structure
        files[name] = serialized

    host = connection['host']

    return host, params, files 
开发者ID:kszucs,项目名称:pandahouse,代码行数:22,代码来源:http.py

示例2: process_pong_v4

# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import valfilter [as 别名]
def process_pong_v4(self, remote: kademlia.Node, token: Hash32) -> None:
        """Process a pong packet.

        Pong packets should only be received as a response to a ping, so the actual processing is
        left to the callback from pong_callbacks, which is added (and removed after it's done
        or timed out) in wait_pong().
        """
        # XXX: This hack is needed because there are lots of parity 1.10 nodes out there that send
        # the wrong token on pong msgs (https://github.com/paritytech/parity/issues/8038). We
        # should get rid of this once there are no longer too many parity 1.10 nodes out there.
        if token in self.parity_pong_tokens:
            # This is a pong from a buggy parity node, so need to lookup the actual token we're
            # expecting.
            token = self.parity_pong_tokens.pop(token)
        else:
            # This is a pong from a non-buggy node, so just cleanup self.parity_pong_tokens.
            self.parity_pong_tokens = toolz.valfilter(
                lambda val: val != token, self.parity_pong_tokens
            )

        pingid = self._mkpingid(token, remote)

        try:
            callback = self.pong_callbacks.get_callback(pingid)
        except KeyError:
            self.logger.debug(
                "unexpected pong from %s (token == %s)", remote, encode_hex(token)
            )
        else:
            callback() 
开发者ID:QuarkChain,项目名称:pyquarkchain,代码行数:32,代码来源:discovery.py

示例3: _read_csv

# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import valfilter [as 别名]
def _read_csv(path, schema, **kwargs):
    dtypes = dict(schema.to_pandas())

    dates = list(toolz.valfilter(lambda s: s == 'datetime64[ns]', dtypes))
    dtypes = toolz.dissoc(dtypes, *dates)

    return pd.read_csv(
        str(path), dtype=dtypes, parse_dates=dates, encoding='utf-8', **kwargs
    ) 
开发者ID:ibis-project,项目名称:ibis,代码行数:11,代码来源:csv.py

示例4: test_curried_namespace

# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import valfilter [as 别名]
def test_curried_namespace():
    def should_curry(value):
        if not callable(value) or isinstance(value, curry) or isinstance(value, type):
            return False
        if isinstance(value, type) and issubclass(value, Exception):
            return False
        nargs = enhanced_num_required_args(value)
        if nargs is None or nargs > 1:
            return True
        else:
            return nargs == 1 and enhanced_has_keywords(value)

    def curry_namespace(ns):
        return dict(
            (name, curry(f) if should_curry(f) else f)
            for name, f in ns.items()
            if "__" not in name
        )

    all_auto_curried = curry_namespace(vars(eth_utils))

    inferred_namespace = valfilter(callable, all_auto_curried)
    curried_namespace = valfilter(callable, eth_utils.curried.__dict__)

    if inferred_namespace != curried_namespace:
        missing = set(inferred_namespace) - set(curried_namespace)
        if missing:
            to_insert = sorted("%s," % f for f in missing)
            raise AssertionError(
                "There are missing functions in eth_utils.curried:\n"
                + "\n".join(to_insert)
            )
        extra = set(curried_namespace) - set(inferred_namespace)
        if extra:
            raise AssertionError(
                "There are extra functions in eth_utils.curried:\n"
                + "\n".join(sorted(extra))
            )
        unequal = merge_with(list, inferred_namespace, curried_namespace)
        unequal = valfilter(lambda x: x[0] != x[1], unequal)
        to_curry = keyfilter(lambda x: should_curry(getattr(eth_utils, x)), unequal)
        if to_curry:
            to_curry_formatted = sorted("{0} = curry({0})".format(f) for f in to_curry)
            raise AssertionError(
                "There are missing functions to curry in eth_utils.curried:\n"
                + "\n".join(to_curry_formatted)
            )
        elif unequal:
            not_to_curry_formatted = sorted(unequal)
            raise AssertionError(
                "Missing functions NOT to curry in eth_utils.curried:\n"
                + "\n".join(not_to_curry_formatted)
            )
        else:
            raise AssertionError(
                "unexplained difference between %r and %r"
                % (inferred_namespace, curried_namespace)
            ) 
开发者ID:ethereum,项目名称:eth-utils,代码行数:60,代码来源:test_curried.py


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