larray.Session.load

Session.load(fname, names=None, engine='auto', display=False, **kwargs) None[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
fnamestr or Path

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 to display which file is being worked on. Defaults to False.

Examples

In one module:

>>> # 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 the session in an HDF5 file
>>> ses.save('input.h5')                                                    

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')                                               
>>> ses                                                                     
Session(a, a01, arr1, arr2, b, i, s)
>>> ses.meta                                                                
title: my title
author: John Smith

Load only some objects

>>> ses = Session()
>>> ses.load('input.h5', names=['s', 'a', 'b', 'arr1', 'arr2'], display=True)   
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')                                                        
>>> ses = Session()                                                         
>>> # load all .csv files from the 'data' directory
>>> ses.load('data', display=True)                                          
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)                                   
opening data/*1.csv
loading Array object arr1 ... done