Skip to main content

grapher.Node

Single workbook cell in a dependency graph.

Usage

Source

grapher.Node()

Canonical identity is address (CellKey). Change it through DependencyGraph.move_node; assigning address directly raises so relative formula axes cannot silently retarget. Legacy constructors that pass sheet/column/row still work and sync address in __init__.

formula_ast is the primary in-memory formula artifact. Construct nodes with formula_ast= when the tree is already known. normalized_formula is a derived view (render_formula with A1_ABSOLUTE); it is not stored, and the constructor keyword of the same name is only a bootstrap for string input. When an address is available, that bootstrap parses with parse_preserving_axes so $ vs bare A1 is kept; without an anchor, relative intent cannot be recovered. Unparseable cells keep the last known formula text as a fallback so has_formula still holds. DependencyGraph.formula_shapes is an optional eval/codegen overlay; missing or dropped shapes fall back to this AST. The raw workbook string formula is opt-in at extraction (create_dependency_graph(store_raw_formula=True)) and audit-only – on a compressed graph it still holds the pre-compression text, so never re-parse it as the node’s current definition.

is_leaf is true when the node has no outgoing dependency edges (value-only cells and literal-only formulas such as =1+1).

is_array_formula is true when extraction observed a fastpyxl ArrayFormula on this cell. array_formula_ref is the spill / CSE range Excel stored (ref, e.g. E1:E10), or None when that attribute was missing. Write-back emits ArrayFormula from these fields and refuses to scalarize a flagged cell whose ref was not observed. fastpyxl does not distinguish legacy CSE from dynamic-array spills; both round-trip as t="array".

Instances are slotted (no per-instance __dict__). Derived attributes (key, shape, column_index) are served from a process-wide LRU keyed on the canonical address rather than functools.cached_property.

metadata is a read-only Mapping for callers. Nodes without metadata share the immutable EMPTY_METADATA singleton instead of allocating a dict, so node.metadata["k"] = v is not supported (it raises TypeError on a node with no metadata yet). Writers — node hooks included — use set_metadata / update_metadata, or DependencyGraph.set_node_metadata.

Dimension binds and key coordinates live on SeriesCatalog, not on this node. key_point(catalog) and dimension_binds(catalog) are thin adapters that return None for unbound cells.

Parameter Attributes

sheet: str | None = None
column: str | None = None
row: int | None = None
formula: str | None = None
value: Any = None
is_leaf: bool = True
is_target: bool = False
metadata: Mapping[str, Any] = EMPTY_METADATA
min_col: str | None = None
min_row: int | None = None
max_col: str | None = None
max_row: int | None = None
address: CellKey | None = None
formula_ast: AstNode | None = None
normalized_formula: str | None = None
is_array_formula: bool = False
array_formula_ref: str | None = None

Attributes

Name Description
has_formula True when this cell has a formula AST or unparseable formula text.

has_formula

True when this cell has a formula AST or unparseable formula text.

has_formula: bool

Methods

Name Description
apply_formula_text() Parse text into formula_ast, or keep it as unparseable fallback.
dimension_binds() Series-level dimension binds for this cell in catalog, or None if unbound.
key_point() Resolved key coordinates for this cell in catalog, or None if unbound.
set_metadata() Replace this node’s metadata with a copy of metadata.
update_metadata() Merge updates into this node’s metadata, allocating on first write.

apply_formula_text()

Parse text into formula_ast, or keep it as unparseable fallback.

Usage

Source

apply_formula_text(text)

When address is set, parse with parse_preserving_axes so $ vs bare A1 is kept. Without an anchor, relative intent cannot be recovered. Clears both when text is missing or blank. Used when a rewrite only has formula strings (the AST parser could not handle the cell).


dimension_binds()

Series-level dimension binds for this cell in catalog, or None if unbound.

Usage

Source

dimension_binds(catalog)

key_point()

Resolved key coordinates for this cell in catalog, or None if unbound.

Usage

Source

key_point(catalog)

catalog is a SeriesCatalog. Returns a KeyPoint when the cell is bound.


set_metadata()

Replace this node’s metadata with a copy of metadata.

Usage

Source

set_metadata(metadata)

Empty or None input drops back to the shared EMPTY_METADATA singleton, so nodes without metadata never own a dict.


update_metadata()

Merge updates into this node’s metadata, allocating on first write.

Usage

Source

update_metadata(updates)