larray.Session.load

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

Load Array objects from a file, or several .csv files (all formats). Load also Axis and Group objects from a file (HDF and pickle formats).

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")    
>>> # groups
>>> a01 = a['a0,a1'] >> 'a01'                    
>>> # arrays
>>> arr1, arr2 = ndtest((a, b)), ndtest(a)       
>>> s = Session([('a', a), ('b', b), ('a01', a01), ('arr1', arr1), ('arr2', arr2)])  
>>> # metadata
>>> s.meta.title = 'my title'                    
>>> s.meta.author = 'John Smith'                 
>>> # save the session in an HDF5 file
>>> s.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
>>> s = Session('input.h5')     
>>> s                           
Session(a, b, a01, arr1, arr2)
>>> s.meta                      
title: my title
author: John Smith

Load only some objects

>>> s = Session()                                   
>>> s.load('input.h5', ['a', 'b', 'arr1', 'arr2'])  
>>> a, b, arr1, arr2 = s['a', 'b', 'arr1', 'arr2']  
>>> # only if you know the order of arrays stored in session
>>> a, b, a01, arr1, arr2 = s.values()              

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

>>> s.save('data')                                
>>> s = Session()                                 
>>> # load all .csv files starting with "output" in the data directory
>>> s.load('data')                                
>>> # or only arrays (i.e. all CSV files starting with 'arr')
>>> s.load('data/arr*.csv')