6.4.3 Load Saved Objects From a Datastore

The oml.ds.load function loads one or more Python objects from a datastore into a Python session.

The syntax of oml.ds.load is the following:

oml.ds.load(name, objs=None, owner=None, to_globals=True)

The name argument specifies the datastore that contains the objects to load.

With the objs argument, you identify a specific object or a list of objects to load.

With the boolean to_globals parameter, you can specify whether the objects are loaded to a global workspace or to a dictionary object. If the argument to to_globals is True, then oml.ds.load function loads the objects into the global workspace. If the argument is False, then the function returns a dict object that contains pairs of object names and values.

The oml.ds.load function raises a ValueError if the name argument is an empty string or if the owner of the datastore is not the current user and the read privilege for the datastore has not been granted to the current user.

Example 6-15 Loading Objects from Datastores

This example loads objects from datastores. For the creation of the datastores used in this example, see Example 6-14.

import oml

# Load all Python objects from a datastore to the global workspace.
sorted(oml.ds.load(name="ds_pydata"))

# Load the named Python object from the datastore to the global workspace.
oml.ds.load(name="ds_pymodel", objs=["regr2"])

# Load the named Python object from the datastore to the user's workspace.
oml.ds.load(name="ds_pymodel", objs=["regr1"], to_globals=False)

Listing for This Example

>>> import oml
>>>
>>> # Load all Python objects from a datastore to the current workspace.
... sorted(oml.ds.load(name="ds_pydata"))
['oml_boston', 'oml_diabetes', 'wine']
>>>
>>> # Load the named Python object from the datastore to the global workspace.
... oml.ds.load(name="ds_pymodel", objs=["regr2"])
['regr2']
>>> 
>>> # Load the named Python object from the datastore to the user's workspace.
... oml.ds.load(name="ds_pymodel", objs=["regr1"], to_globals=False)
{'regr1': LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False)}