本文整理汇总了Python中toolz.curry方法的典型用法代码示例。如果您正苦于以下问题:Python toolz.curry方法的具体用法?Python toolz.curry怎么用?Python toolz.curry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类toolz
的用法示例。
在下文中一共展示了toolz.curry方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ensure_doctest
# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import curry [as 别名]
def ensure_doctest(f, name=None):
"""Ensure that an object gets doctested. This is useful for instances
of objects like curry or partial which are not discovered by default.
Parameters
----------
f : any
The thing to doctest.
name : str, optional
The name to use in the doctest function mapping. If this is None,
Then ``f.__name__`` will be used.
Returns
-------
f : any
``f`` unchanged.
"""
_getframe(2).f_globals.setdefault('__test__', {})[
f.__name__ if name is None else name
] = f
return f
示例2: get
# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import curry [as 别名]
def get(self) -> Optional[PluginType]:
"""Return the currently active plugin."""
if self._options:
return curry(self._active, **self._options)
else:
return self._active
示例3: test_build_pipeline_learner_assertion
# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import curry [as 别名]
def test_build_pipeline_learner_assertion(has_repeated_learners):
@fp.curry
def learner(df, a, b, c=3):
return lambda dataset: dataset + a + b + c, df, {}
learner_fn = learner(b=2)
with pytest.raises(ValueError):
build_pipeline(learner_fn, has_repeated_learners=has_repeated_learners)
learner_fn = learner(a=1, b=2)
build_pipeline(learner_fn)
示例4: test_build_pipeline_predict_arguments_assertion
# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import curry [as 别名]
def test_build_pipeline_predict_arguments_assertion(has_repeated_learners):
test_df = pd.DataFrame({"x": [1, 2, 3, 4, 5], "y": [2, 4, 6, 8, 10]})
@fp.curry
def invalid_learner(df):
def p(dataset, *a, **b):
return dataset + len(a) + len(b)
return p, df, {}
with pytest.raises(ValueError):
build_pipeline(invalid_learner, has_repeated_learners=has_repeated_learners)(test_df)
示例5: test_build_pipeline_serialisation
# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import curry [as 别名]
def test_build_pipeline_serialisation():
df_train = pd.DataFrame({
'id': ["id1"],
'x1': [10.0],
'y': [2.3]
})
fn = lambda x: x
@fp.curry
def dummy_learner(df, fn, call):
return fn, df, {f"dummy_learner_{call}": {}}
@fp.curry
def dummy_learner_2(df, fn, call):
return dummy_learner(df, fn, call)
@fp.curry
def dummy_learner_3(df, fn, call):
return fn, df, {f"dummy_learner_{call}": {}, "obj": "a"}
train_fn = build_pipeline(
dummy_learner(fn=fn, call=1),
dummy_learner_2(fn=fn, call=2),
dummy_learner_3(fn=fn, call=3))
predict_fn, pred_train, log = train_fn(df_train)
fkml = {"pipeline": ["dummy_learner", "dummy_learner_2", "dummy_learner_3"],
"output_columns": ['id', 'x1', 'y'],
"features": ['id', 'x1', 'y'],
"learners": {"dummy_learner": {"fn": fn, "log": {"dummy_learner_1": {}}},
"dummy_learner_2": {"fn": fn, "log": {"dummy_learner_2": {}}},
"dummy_learner_3": {"fn": fn, "log": {"dummy_learner_3": {}}, "obj": "a"}}}
assert log["__fkml__"] == fkml
assert "obj" not in log.keys()
示例6: test_build_pipeline_repeated_learners_serialisation
# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import curry [as 别名]
def test_build_pipeline_repeated_learners_serialisation():
df_train = pd.DataFrame({
'id': ["id1"],
'x1': [10.0],
'y': [2.3]
})
fn = lambda x: x
@fp.curry
def dummy_learner(df, fn, call):
return fn, df, {f"dummy_learner_{call}": {}}
@fp.curry
def dummy_learner_2(df, fn, call):
return dummy_learner(df, fn, call)
train_fn = build_pipeline(
dummy_learner(fn=fn, call=1),
dummy_learner_2(fn=fn, call=2),
dummy_learner(fn=fn, call=3),
has_repeated_learners=True)
predict_fn, pred_train, log = train_fn(df_train)
fkml = {"pipeline": ["dummy_learner", "dummy_learner_2", "dummy_learner"],
"output_columns": ['id', 'x1', 'y'],
"features": ['id', 'x1', 'y'],
"learners": {
"dummy_learner": [
{"fn": fn, "log": {"dummy_learner_1": {}}},
{"fn": fn, "log": {"dummy_learner_3": {}}}],
"dummy_learner_2": [{"fn": fn, "log": {"dummy_learner_2": {}}}]}}
assert log["__fkml__"] == fkml
assert "obj" not in log.keys()
示例7: test_curried_namespace
# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import curry [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)
)