Python toolz.valfilter() Examples
The following are 4
code examples of toolz.valfilter().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
toolz
, or try the search function
.
Example #1
Source File: http.py From pandahouse with MIT License | 6 votes |
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
Example #2
Source File: discovery.py From pyquarkchain with MIT License | 5 votes |
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()
Example #3
Source File: csv.py From ibis with Apache License 2.0 | 5 votes |
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 )
Example #4
Source File: test_curried.py From eth-utils with MIT License | 4 votes |
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) )