UserSpace#

class UserSpace(_impl)[source]#

Editable space serving as a container for cells, child spaces, and references.

UserSpace is the primary space type that users create and modify directly. It serves as a static, editable container that can hold:

  • Cells objects (formulas with cached values)

  • Child UserSpace objects (nested spaces)

  • References to external objects (data, modules, etc.)

UserSpaces can be parameterized with a formula, which enables the creation of ItemSpace instances dynamically when accessed with arguments.

UserSpaces support inheritance through base spaces, allowing cells and references to be inherited and overridden in derived spaces.

Key Characteristics:

  • Editable: Cells, spaces, and references can be added, modified, or removed

  • Static: Exists independently of any parameter values

  • Named: Has a fixed name within its parent’s namespace

  • Inheritable: Can serve as a base for other UserSpaces

See also

DynamicSpace: Read-only spaces created dynamically ItemSpace: Parameterized instances of spaces new_space(): Create a new UserSpace in a model

Changed in version 0.0.23: Renamed from StaticSpace to UserSpace

Basic properties#

name

Name of the object.

fullname

Dotted name of the object.

doc

Documentation string

allow_none

Whether a cells can have None as its value.

model

The model this object belongs to.

parent

The parent of this object.

properties

refs

Read-only mapping of reference names to their values.

has_params()

Check whether this space has parameters defined.

set_property(name, value)

Set property name

info

An object whose repr summarizes this Interface.

Space operations#

copy(parent[, name, defined_only])

Create a copy of this space in a different parent.

rename(name)

Rename this space to a new name.

Inheritance operations#

bases

List of base spaces from which this space inherits.

add_bases(*bases)

Add base spaces for inheritance.

remove_bases(*bases)

Remove base spaces from inheritance hierarchy.

Child Space operations#

spaces

Read-only mapping of names to child UserSpace objects.

named_spaces

Read-only mapping of names to child UserSpace objects.

static_spaces

A mapping associating names to named spaces.

cur_space([name])

Set the current space to Space name and return it.

import_module([module, recursive])

Create a child space from an module.

new_space([name, bases, formula, refs])

Create a child space.

new_space_from_csv(filepath[, space, cells, ...])

Create spaces from from a comma-separated values (csv) file.

new_space_from_excel(book, range_[, sheet, ...])

Create a child space from an Excel range.

new_space_from_module(module[, recursive])

Create a child space from an module.

new_space_from_pandas(obj[, space, cells, ...])

Create child spaces from Pandas DataFrame or Series.

reload()

Reload the source module and update the formulas.

clear_all()

Clear all cell values and delete all ItemSpaces recursively.

Child Cells operations#

cells

Read-only mapping of cells names to Cells objects.

new_cells([name, formula, is_cached])

Create a new Cells object in this space.

new_cells_from_csv(filepath[, cells, param])

Create cells from a comma-separated values (csv) file.

new_cells_from_excel(book, range_[, sheet, ...])

Create multiple cells from an Excel range.

new_cells_from_module(module)

Create multiple cells from functions defined in a Python module.

new_cells_from_pandas(obj[, cells, param])

Create new cells from Pandas Series or DataFrame object.

import_funcs(module)

Create a cells from a module.

clear_cells([clear_input, recursive])

Clear values from cells with flexible control over scope.

sort_cells()

Sort child cells alphabetically by name.

Reference operations#

set_ref(name, value, refmode)

Set a reference with explicit mode control.

absref(**kwargs)

Set references in absolute mode.

relref(**kwargs)

Set references in relative mode.

new_excel_range(name, path, range_[, sheet, ...])

Creates a Reference to an Excel range

new_pandas(name, path, data[, file_type, ...])

Create a Reference bound to a pandas DataFrame or Series associating a new PandasData object.

new_module(name, path, module)

Assigns a user module to a Reference associating a new ModuleData object

ItemSpace operations#

itemspaces

Read-only mapping of parameter arguments to ItemSpace objects.

parameters

Tuple of parameter names for this space, or None if not parameterized.

formula

The formula that defines parameter behavior for this space.

set_formula(formula)

Set the parameter formula for this space.

del_formula()

Delete the parameter formula from this space.

clear_items()

Delete all ItemSpace objects in this space.

clear_at(*args, **kwargs)

Delete a child ItemSpace object

node(*args, **kwargs)

Return a Node object for the given arguments.

preds(*args, **kwargs)

Return a list of predecessors of a cell.

succs(*args, **kwargs)

Return a list of successors of a cell.

precedents(*args, **kwargs)

Return a list of the precedents.

Exporting to Pandas objects#

frame

Alias of to_frame().

to_frame(*args)

Convert cells in this space to a pandas DataFrame.