larray.Session.load¶
-
Session.
load
(self, fname, names=None, engine='auto', display=False, **kwargs)[source]¶ Load LArray, Axis and Group objects from a file, or several .csv files.
WARNING: never load a file using the pickle engine (.pkl or .pickle) from an untrusted source, as it can lead to arbitrary code execution.
- Parameters
- fnamestr
This can be either the path to a single file, a path to a directory containing .csv files or a pattern representing several .csv files.
- nameslist of str, optional
List of objects to load. If fname is None, list of paths to CSV files. Defaults to all valid objects present in the file/directory.
- engine{‘auto’, ‘pandas_csv’, ‘pandas_hdf’, ‘pandas_excel’, ‘xlwings_excel’, ‘pickle’}, optional
Load using engine. Defaults to ‘auto’ (use default engine for the format guessed from the file extension).
- displaybool, optional
Whether or not to display which file is being worked on. Defaults to False.
Examples
In one module:
>>> # 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 >>> s = Session([('a', a), ('b', b), ('a01', a01), ('arr1', arr1), ('arr2', arr2)]) # doctest: +SKIP >>> # metadata >>> s.meta.title = 'my title' # doctest: +SKIP >>> s.meta.author = 'John Smith' # doctest: +SKIP >>> # save the session in an HDF5 file >>> s.save('input.h5') # doctest: +SKIP
In another module: load the whole session
>>> # the load method is automatically called when passing >>> # the path of file to the Session constructor >>> s = Session('input.h5') # doctest: +SKIP >>> s # doctest: +SKIP Session(a, b, a01, arr1, arr2) >>> s.meta # doctest: +SKIP title: my title author: John Smith
Load only some objects
>>> s = Session() # doctest: +SKIP >>> s.load('input.h5', ['a', 'b', 'arr1', 'arr2']) # doctest: +SKIP >>> a, b, arr1, arr2 = s['a', 'b', 'arr1', 'arr2'] # doctest: +SKIP >>> # only if you know the order of arrays stored in session >>> a, b, a01, arr1, arr2 = s.values() # doctest: +SKIP
Using .csv files (assuming the same session as above)
>>> s.save('data') # doctest: +SKIP >>> s = Session() # doctest: +SKIP >>> # load all .csv files starting with "output" in the data directory >>> s.load('data') # doctest: +SKIP >>> # or only arrays (i.e. all CSV files starting with 'arr') >>> s.load('data/arr*.csv') # doctest: +SKIP