larray.Session

class larray.Session(*args, **kwargs)[source]

Groups several objects together.

Parameters
*argsstr or dict of {str: object} or iterable of tuples (str, object)

Path to the file containing the session to load or list/tuple/dictionary containing couples (name, object).

**kwargsdict of {str: object}
  • Objects to add written as name=object

  • metalist of pairs or dict or OrderedDict or Metadata

    Metadata (title, description, author, creation_date, …) associated with the array. Keys must be strings. Values must be of type string, int, float, date, time or datetime.

Warning

Metadata is not kept when actions or methods are applied on a session except for operations modifying a specific array, such as: s[‘arr1’] = 0. Do not add metadata to a session if you know you will apply actions or methods on it before dumping it.

Examples

>>> # 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)

create a Session by passing a list of pairs (name, object)

>>> s = Session([('a', a), ('b', b), ('a01', a01), ('arr1', arr1), ('arr2', arr2)])

create a Session using keyword arguments (but you lose order on Python < 3.6)

>>> s = Session(a=a, b=b, a01=a01, arr1=arr1, arr2=arr2)

create a Session by passing a dictionary (but you lose order on Python < 3.6)

>>> s = Session({'a': a, 'b': b, 'a01': a01, 'arr1': arr1, 'arr2': arr2})

load Session from file

>>> s = Session('my_session.h5')  # doctest: +SKIP

create a session with metadata

>>> # Python <= 3.5
>>> s = Session([('arr1', arr1), ('arr2', arr2)], meta=[('title', 'my title'), ('author', 'John Smith')])
>>> s.meta
title: my title
author: John Smith
>>> # Python 3.6+
>>> s = Session(arr1=arr1, arr2=arr2, meta=Metadata(title='my title', author='John Smith'))  # doctest: +SKIP
>>> s.meta
title: my title
author: John Smith
__init__(self, *args, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(self, \*args, \*\*kwargs)

Initialize self.

add(self, \*args, \*\*kwargs)

Adds objects to the current session.

apply(self, func, \*args, \*\*kwargs)

Apply function func on elements of the session and return a new session.

array_equals(\*args, \*\*kwargs)

compact(self[, display])

Detects and removes “useless” axes (ie axes for which values are constant over the whole axis) for all array objects in session

copy(self)

Returns a copy of the session.

dump(\*args, \*\*kwargs)

dump_csv(\*args, \*\*kwargs)

dump_excel(\*args, \*\*kwargs)

dump_hdf(\*args, \*\*kwargs)

element_equals(self, other)

Test if each element (group, axis and array) of the current session equals the corresponding element of another session.

equals(self, other)

Test if all elements (groups, axes and arrays) of the current session are equal to those of another session.

filter(self[, pattern, kind])

Returns a new session with objects which match some criteria.

get(self, key[, default])

Returns the object corresponding to the key.

items(self)

Returns a view of the session’s items ((key, value) pairs).

keys(self)

Returns a view on the session’s keys.

load(self, fname[, names, engine, display])

Load LArray, Axis and Group objects from a file, or several .csv files.

save(self, fname[, names, engine, …])

Dumps LArray, Axis and Group objects from the current session to a file.

summary(self[, template])

Returns a summary of the content of the session.

to_csv(self, fname[, names, display])

Dumps LArray, Axis and Group objects from the current session to CSV files.

to_excel(self, fname[, names, overwrite, …])

Dumps LArray, Axis and Group objects from the current session to an Excel file.

to_globals(self[, names, depth, warn, inplace])

Create global variables out of objects in the session.

to_hdf(self, fname[, names, overwrite, display])

Dumps LArray, Axis and Group objects from the current session to an HDF file.

to_pickle(self, fname[, names, overwrite, …])

Dumps LArray, Axis and Group objects from the current session to a file using pickle.

transpose(self, \*args)

Reorder axes of arrays in session, ignoring missing axes for each array.

update(self[, other])

Update the session with the key/value pairs from other or passed keyword arguments, overwriting existing keys.

values(self)

Returns a view on the session’s values.

Attributes

names

Returns the list of names of the objects in the session.