UserSpace.set_ref#

UserSpace.set_ref(name, value, refmode)[source]#

Set a reference with explicit mode control.

Creates or updates a reference that makes an object accessible as a global variable within this space’s formulas. The reference mode determines how the reference behaves in inheritance contexts.

Reference Modes:

  • “auto”: Automatically choose based on scope (default)

  • “absolute”: Fixed binding, never adjusts for inheritance

  • “relative”: Binding adjusts based on derived space context

Parameters:
  • name (str) – Name for the reference. Must be a valid Python identifier and not conflict with existing cells or spaces.

  • value – The object to reference. Can be any Python object including cells, spaces, data structures, modules, etc.

  • refmode (str) – Reference mode - must be “auto”, “absolute”, or “relative”.

Raises:

Example

>>> import pandas as pd
>>> space = model.new_space('Analysis')

>>> # Set reference to data
>>> df = pd.DataFrame({'A': [1, 2, 3]})
>>> space.set_ref('data', df, refmode='auto')

>>> # Set reference to another cells
>>> other_space = model.new_space('Other')
>>> other_space.new_cells('calc', lambda x: x * 2)
>>> space.set_ref('external_calc', other_space.calc, refmode='absolute')

>>> # Use references in formulas
>>> @mx.defcells(space=space)
... def process():
...     return data['A'].sum() + external_calc(10)

See also

  • absref(): Convenience method for absolute references

  • relref(): Convenience method for relative references

  • refs: View all references in this space