Cells

class modelx.core.cells.Cells[source]

Bases: modelx.core.base.Interface, collections.abc.Mapping, collections.abc.Callable

Data container with a formula to calculate its own values.

Cells are created by new_cells method or its variant methods of the containing space, or by function definitions with defcells decorator.

Methods

clear(*args, **kwargs) Clear all the values.
clear_formula() Clear the formula.
copy([space, name]) Make a copy of itself and return it.
get(k[,d])
items()
keys()
match(*args, **kwargs) Returns the best matching args and their value.
node(*args, **kwargs) Return a CellNode object for the given arguments.
preds(*args, **kwargs) Return a list of predecessors of a cell.
set_formula(func) Set formula from a function.
set_property(name, value) Set property name
succs(*args, **kwargs) Return a list of successors of a cell.
to_frame(*args) Convert the cells itself into a Pandas DataFrame and return it.
to_series(*args) Convert the cells itself into a Pandas Series and return it.
values()

Attributes

allow_none Whether a cells can have None as its value.
doc Description string
formula Property to get, set, delete formula.
frame Alias of to_frame().
fullname Dotted name of the object.
model The model this object belongs to.
name Name of the object.
parameters A tuple of parameter strings.
parent The parent of this object.
properties
series Alias of to_series().
value Get, set, delete the scalar value.
match(*args, **kwargs)[source]

Returns the best matching args and their value.

If the cells returns None for the given arguments, continue to get a value by passing arguments masking the given arguments with Nones. The search of non-None value starts from the given arguments to the all None arguments in the lexicographical order. The masked arguments that returns non-None value first is returned with the value.

copy(space=None, name=None)[source]

Make a copy of itself and return it.

clear(*args, **kwargs)[source]

Clear all the values.

to_series(*args)[source]

Convert the cells itself into a Pandas Series and return it.

series

Alias of to_series().

to_frame(*args)[source]

Convert the cells itself into a Pandas DataFrame and return it.

if no args are passed, the returned DataFrame contains as many values as the cells have.

if A sequence of arguments to the cells is passed as args, the returned DataFrame contains values only for the specified args.

Parameters:args – A sequence or iterable of arguments to the cells.
Returns:a DataFrame with a column named after the cells, with indexes named after the parameters of the cells.
frame

Alias of to_frame().

formula

Property to get, set, delete formula.

parameters

A tuple of parameter strings.

set_formula(func)[source]

Set formula from a function. Deprecated since version 0.0.5. Use formula property instead.

clear_formula()[source]

Clear the formula. Deprecated since version 0.0.5. Use formula property instead.

value

Get, set, delete the scalar value. The cells must be a scalar cells.

node(*args, **kwargs)[source]

Return a CellNode object for the given arguments.

preds(*args, **kwargs)[source]

Return a list of predecessors of a cell.

This method returns a list of CellNode objects, whose elements are predecessors of (i.e. referenced in the formula of) the cell specified by the given arguments.

succs(*args, **kwargs)[source]

Return a list of successors of a cell.

This method returns a list of CellNode objects, whose elements are successors of (i.e. referencing in their formulas) the cell specified by the given arguments.

_baseattrs

A dict of members expressed in literals

_to_attrdict(attrs=None)

Get extra attributes

allow_none

Whether a cells can have None as its value.

This is a property of Model, Space and Cells. If allow_none of a cells is False, the cells cannot have None as its value. Assigning None to the cells or its formula returning None raises an Error. If True, the cells can have None as their value. If set to None, allow_none of its parent is looked up, and the search continues until True or False is found.

Returns:True if the cells can have None, False if it cannot, or None if a default value from the parent is to be used.
doc

Description string

When models or spaces are imported from modules, taken from modules docstring. For cells, set to its formula’s docstring.

fullname

Dotted name of the object.

Names joined by dots, such as ‘Model1.Space1.Cells1’, each element in the string is the name of the parent object of the next one joined by a dot.

get(k[, d]) → D[k] if k in D, else d. d defaults to None.
items() → a set-like object providing a view on D's items
keys() → a set-like object providing a view on D's keys
model

The model this object belongs to.

This is a property of Model, Space and Cells. For models, this property is themselves.

name

Name of the object.

parent

The parent of this object. None for models.

The parent object of a cells is a space that contains the cells. The parent object of a space is either a model or another space that contains the space.

set_property(name: str, value)

Set property name

Set value to property name of an interface. Equivalent to x.name = value, where x is a Model/Space/Cells object.

values() → an object providing a view on D's values