本文整理汇总了Python中toolz.pipe方法的典型用法代码示例。如果您正苦于以下问题:Python toolz.pipe方法的具体用法?Python toolz.pipe怎么用?Python toolz.pipe使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类toolz
的用法示例。
在下文中一共展示了toolz.pipe方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sample
# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import pipe [as 别名]
def test_sample():
"""Test the sample data transformer."""
data = _create_dataframe(20)
result = pipe(data, sample(n=10))
assert len(result) == 10
assert isinstance(result, pd.DataFrame)
data = _create_data_with_values(20)
result = sample(data, n=10)
assert isinstance(result, dict)
assert "values" in result
assert len(result["values"]) == 10
data = _create_dataframe(20)
result = pipe(data, sample(frac=0.5))
assert len(result) == 10
assert isinstance(result, pd.DataFrame)
data = _create_data_with_values(20)
result = sample(data, frac=0.5)
assert isinstance(result, dict)
assert "values" in result
assert len(result["values"]) == 10
示例2: test_dataframe_to_json
# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import pipe [as 别名]
def test_dataframe_to_json():
"""Test to_json
- make certain the filename is deterministic
- make certain the file contents match the data
"""
data = _create_dataframe(10)
try:
result1 = pipe(data, to_json)
result2 = pipe(data, to_json)
filename = result1["url"]
output = pd.read_json(filename)
finally:
os.remove(filename)
assert result1 == result2
assert output.equals(data)
示例3: test_dataframe_to_csv
# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import pipe [as 别名]
def test_dataframe_to_csv():
"""Test to_csv with dataframe input
- make certain the filename is deterministic
- make certain the file contents match the data
"""
data = _create_dataframe(10)
try:
result1 = pipe(data, to_csv)
result2 = pipe(data, to_csv)
filename = result1["url"]
output = pd.read_csv(filename)
finally:
os.remove(filename)
assert result1 == result2
assert output.equals(data)
示例4: test_dict_to_csv
# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import pipe [as 别名]
def test_dict_to_csv():
"""Test to_csv with dict input
- make certain the filename is deterministic
- make certain the file contents match the data
"""
data = _create_data_with_values(10)
try:
result1 = pipe(data, to_csv)
result2 = pipe(data, to_csv)
filename = result1["url"]
output = pd.read_csv(filename).to_dict(orient="records")
finally:
os.remove(filename)
assert result1 == result2
assert data == {"values": output}
示例5: _valid_log_files
# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import pipe [as 别名]
def _valid_log_files(log_dir):
def _valid_or_warn(log_file):
if log_file.has_valid_filename():
return True
logging.warning("Invalid filename: %s", log_file.filename())
return False
def _to_paths(triple):
root, _, files_in_dir = triple
return [os.path.join(root, file_in_dir) for file_in_dir in files_in_dir]
return pipe(os.walk(log_dir),
mapcatz(_to_paths),
mapz(LogFile),
filterz(_valid_or_warn))
示例6: plot
# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import pipe [as 别名]
def plot(self, gpu_measurement='sm', num_gpus=1, plot_width=600, plot_height=400, y_range=(0, 110)):
""" Plot the specified GPU measurement
Parameters
----------
gpu_measurement: GPU measurement to plot possible values
num_gpus: Number of GPUs to plot ['pwr', 'temp', 'sm', 'mem', 'enc', 'dec', 'mclk', 'pclk']
plot_width:
plot_height:
y_range:
Returns
-------
Bokeh Figure
"""
df = pipe(self._log_file,
parse_log,
extract(gpu_measurement))
return plot(df,
num_gpus=num_gpus,
plot_width=plot_width,
plot_height=plot_height,
y_range=y_range)
示例7: get_contract_address
# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import pipe [as 别名]
def get_contract_address(task_uuid):
await_tr = partial(await_blockchain_success_evil, timeout=timeout)
return pipe(task_uuid, await_tr, lambda r: r.get('contract_address'))
示例8: _open_image
# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import pipe [as 别名]
def _open_image(self, image_path):
return pipe(image_path, _open_to_array, _rescale)
示例9: _open_mask
# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import pipe [as 别名]
def _open_mask(self, mask_path):
return pipe(mask_path, _open_to_array)
示例10: test_limit_rows
# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import pipe [as 别名]
def test_limit_rows():
"""Test the limit_rows data transformer."""
data = _create_dataframe(10)
result = limit_rows(data, max_rows=20)
assert data is result
with pytest.raises(MaxRowsError):
pipe(data, limit_rows(max_rows=5))
data = _create_data_with_values(10)
result = pipe(data, limit_rows(max_rows=20))
assert data is result
with pytest.raises(MaxRowsError):
limit_rows(data, max_rows=5)
示例11: test_to_values
# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import pipe [as 别名]
def test_to_values():
"""Test the to_values data transformer."""
data = _create_dataframe(10)
result = pipe(data, to_values)
assert result == {"values": data.to_dict(orient="records")}
示例12: test_type_error
# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import pipe [as 别名]
def test_type_error():
"""Ensure that TypeError is raised for types other than dict/DataFrame."""
for f in (sample, limit_rows, to_values):
with pytest.raises(TypeError):
pipe(0, f)
示例13: __call__
# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import pipe [as 别名]
def __call__(self, coords):
return tz.pipe(coords, *self)
示例14: simplified
# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import pipe [as 别名]
def simplified(self) -> 'Transform':
"""Return the composite of the transforms inside the transform chain."""
if len(self) == 0:
return None
if len(self) == 1:
return self[0]
else:
return tz.pipe(self[0], *[tf.compose for tf in self[1:]])
示例15: last_event_timestamp_in_dir
# 需要导入模块: import toolz [as 别名]
# 或者: from toolz import pipe [as 别名]
def last_event_timestamp_in_dir(log_dir):
"""Return the timestamp of the most recent event in the given directory"""
most_recent_file = pipe(_valid_log_files(log_dir),
sortedz(key=LogFile.timestamp),
lastz,
LogFile.records,
sortedz(key=lambda record: record.event_time),
lastz)
return most_recent_file.event_time