larray.Session.save

Session.save(fname, names=None, engine='auto', overwrite=True, display=False, **kwargs)[source]

Dumps 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:
fname : str

Path of the file for the dump. If objects are saved in CSV files, the path corresponds to a directory.

names : list 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 or not to overwrite an existing file, if any. Ignored for CSV files and ‘pandas_excel’ engine. If False, file is updated. Defaults to True.

display : bool, optional

Whether or not to display which file is being worked on. Defaults to False.

Examples

>>> # scalars
>>> i, s = 5, 'string'                                                      # doctest: +SKIP
>>> # axes
>>> a, b = Axis("a=a0..a2"), Axis("b=b0..b2")                               # doctest: +SKIP
>>> # groups
>>> a01 = a['a0,a1'] >> 'a01'                                               # doctest: +SKIP
>>> # arrays
>>> arr1, arr2 = ndtest((a, b)), ndtest(a)                                  # doctest: +SKIP
>>> ses = Session([('i', i), ('s', s), ('a', a), ('b', b), ('a01', a01),
...                ('arr1', arr1), ('arr2', arr2)])                         # doctest: +SKIP
>>> # metadata
>>> ses.meta.title = 'my title'                                             # doctest: +SKIP
>>> ses.meta.author = 'John Smith'                                          # doctest: +SKIP

Save all objects

>>> ses.save('output.h5', display=True)                                     # doctest: +SKIP
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)  # doctest: +SKIP
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))                             # doctest: +SKIP
>>> ses2 = Session([('arr1', arr1), ('arr4', arr4)])                        # doctest: +SKIP
>>> # replace arr1 and add arr4 in file output.h5
>>> ses2.save('output.h5', overwrite=False, display=True)                   # doctest: +SKIP
dumping arr1 ... done
dumping arr4 ... done