本文整理汇总了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
示例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()
示例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
)
示例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)
)