def fake_metta(matrix_dict, metadata):
"""Stores matrix and metadata in a metta-data-like form
Args:
matrix_dict (dict) of form { columns: values }.
Expects an entity_id to be present which it will use as the index
metadata (dict). Any metadata that should be set
Yields:
tuple of filenames for matrix and metadata
"""
matrix = pandas.DataFrame.from_dict(matrix_dict).set_index('entity_id')
with tempfile.NamedTemporaryFile() as matrix_file:
with tempfile.NamedTemporaryFile('w') as metadata_file:
hdf = pandas.HDFStore(matrix_file.name)
hdf.put('title', matrix, data_columns=True)
matrix_file.seek(0)
yaml.dump(metadata, metadata_file)
metadata_file.seek(0)
yield (matrix_file.name, metadata_file.name)
评论列表
文章目录