larray.Session.save
- Session.save(fname, names=None, engine='auto', overwrite=True, display=False, **kwargs) None [source]
Dump objects from the current session to a file, or several .csv files. The Excel and CSV formats only dump objects of Array type (plus metadata).
- Parameters
- fnamestr or Path
Path of the file for the dump. If objects are saved in CSV files, the path corresponds to a directory.
- nameslist of str or None, optional
List of names of objects to dump. If fname is None, list of paths to CSV files. Defaults to all objects present in the Session.
- engine{‘auto’, ‘pandas_csv’, ‘pandas_hdf’, ‘pandas_excel’, ‘xlwings_excel’, ‘pickle’}, optional
Dump using engine. Defaults to ‘auto’ (use default engine for the format guessed from the file extension).
- overwrite: bool, optional
Whether to overwrite an existing file, if any. Ignored for CSV files and ‘pandas_excel’ engine. If False, file is updated. Defaults to True.
- displaybool, optional
Whether to display which file is being worked on. Defaults to False.
Examples
>>> # scalars >>> i, s = 5, 'string' >>> # axes >>> a, b = Axis("a=a0..a2"), Axis("b=b0..b2") >>> # groups >>> a01 = a['a0,a1'] >> 'a01' >>> # arrays >>> arr1, arr2 = ndtest((a, b)), ndtest(a) >>> ses = Session({'i': i, 's': s, 'a': a, 'b': b, 'a01': a01, ... 'arr1': arr1, 'arr2': arr2}) >>> # metadata >>> ses.meta.title = 'my title' >>> ses.meta.author = 'John Smith'
Save all objects
>>> ses.save('output.h5', display=True) dumping i ... done dumping s ... done dumping a ... done dumping b ... done dumping a01 ... done dumping arr1 ... done dumping arr2 ... done
Save only some objects
>>> ses.save('output.h5', names=['s', 'a', 'b', 'arr1', 'arr2'], display=True) dumping s ... done dumping a ... done dumping b ... done dumping arr1 ... done dumping arr2 ... done
Update file
>>> arr1, arr4 = ndtest((3, 3)), ndtest((2, 3)) >>> ses2 = Session({'arr1': arr1, 'arr4': arr4}) >>> # replace arr1 and add arr4 in file output.h5 >>> ses2.save('output.h5', overwrite=False, display=True) dumping arr1 ... done dumping arr4 ... done