本文整理汇总了Python中toolz.identity方法的典型用法代码示例。如果您正苦于以下问题:Python toolz.identity方法的具体用法?Python toolz.identity怎么用?Python toolz.identity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类toolz
的用法示例。
在下文中一共展示了toolz.identity方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute_series_lead_lag
# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import identity [as 别名]
def execute_series_lead_lag(op, data, offset, default, **kwargs):
func = toolz.identity if isinstance(op, ops.Lag) else operator.neg
result = data.shift(func(1 if offset is None else offset))
return post_lead_lag(result, default)
示例2: format_results
# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import identity [as 别名]
def format_results(terminal_width, key_list, separator, text_list,
left_align=True, min_factor=3, **kwargs):
"""Returns formatted results in two columns.
"""
key_width = max(map(len, key_list))
separator_length = len(separator)
desc_wrap = toolz.identity
if terminal_width:
if key_width / terminal_width > .5:
key_width = terminal_width // 2 - 3
text_width = terminal_width - key_width - separator_length
if text_width * min_factor > terminal_width:
desc_wrap = toolz.compose(
('\n' + ' ' * (key_width + separator_length)).join,
toolz.partial(textwrap.wrap, width=text_width, **kwargs),
)
if left_align:
fmt = '%-*s%s%s'
else:
fmt = '%*s%s%s'
for key, text in zip(key_list, text_list):
text = desc_wrap(text)
if len(key) > key_width:
yield fmt % (key_width, key, separator, '')
yield fmt % (key_width, '', ' ' * separator_length, text)
else:
yield fmt % (key_width, key, separator, text)
示例3: __init__
# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import identity [as 别名]
def __init__(self, func=tz.identity, inverse=None, name=None):
self.func = func
self._inverse_func = inverse
self.name = name
if func is tz.identity:
self._inverse_func = tz.identity
示例4: apply_async
# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import identity [as 别名]
def apply_async(f, args=(), kwargs=None, callback=None):
"""Apply a function but emulate the API of an asynchronous call.
Parameters
----------
f : callable
The function to call.
args : tuple, optional
The positional arguments.
kwargs : dict, optional
The keyword arguments.
Returns
-------
future : ApplyAsyncResult
The result of calling the function boxed in a future-like api.
Notes
-----
This calls the function eagerly but wraps it so that ``SequentialPool``
can be used where a :class:`multiprocessing.Pool` or
:class:`gevent.pool.Pool` would be used.
"""
try:
value = (identity if callback is None else callback)(
f(*args, **kwargs or {}),
)
successful = True
except Exception as e:
value = e
successful = False
return ApplyAsyncResult(value, successful)