當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。