larray.Session.load

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

Load objects from a file, or several .csv files. The Excel and CSV formats can only contain objects of Array type (plus metadata).

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

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.

names : list 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).

display : bool, optional

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

Examples

In one module:

>>> # 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 the session in an HDF5 file
>>> ses.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
>>> ses = Session('input.h5')                                               # doctest: +SKIP
>>> ses                                                                     # doctest: +SKIP
Session(a, a01, arr1, arr2, b, i, s)
>>> ses.meta                                                                # doctest: +SKIP
title: my title
author: John Smith

Load only some objects

>>> ses = Session()
>>> ses.load('input.h5', names=['s', 'a', 'b', 'arr1', 'arr2'], display=True)   # doctest: +SKIP
opening input.h5
loading Axis object a ... done
loading Array object arr1 ... done
loading Array object arr2 ... done
loading Axis object b ... done
loading str object s ... done

Using .csv files (assuming the same session as above)

>>> ses.save('data')                                                        # doctest: +SKIP
>>> ses = Session()                                                         # doctest: +SKIP
>>> # load all .csv files from the 'data' directory
>>> ses.load('data', display=True)                                          # doctest: +SKIP
opening data
loading Array object arr1 ... done
loading Array object arr2 ... done
>>> # or only arrays containing the character '1' in their names
>>> ses.load('data/*1.csv', display=True)                                   # doctest: +SKIP
opening data/*1.csv
loading Array object arr1 ... done