Attributes
Attribute table helpers from annnet.core._Annotation.
These methods are mixed into AnnNet. Direct imports from underscore modules
follow the internal API policy.
AttributesAccessor is what G.attrs gives back: the eight attribute tables and
the setters that write them. For how those tables relate to the frames under
G.views, and to the older obs/var/slice_attributes spellings, see
Reading the graph and
Internal representation.
annnet.core._Annotation.AttributesClass
Attribute accessors and upsert helpers (graph/node/edge/slice/edge-slice).
Functions
set_graph_attribute
Set a graph-level attribute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Attribute name. |
required |
value
|
Any
|
Attribute value. |
required |
get_graph_attribute
Get a graph-level attribute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Attribute name. |
required |
default
|
Any
|
Value to return if the attribute is missing. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
|
set_node_attrs
Upsert pure node attributes (non-structural) into the node table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
str
|
Node identifier. |
required |
**attrs
|
Attribute key/value pairs. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If any key is structurally reserved (e.g. |
set_node_attrs_bulk
Upsert node attributes in bulk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
updates
|
dict[str, dict] | Iterable[tuple[str, dict]]
|
Mapping or iterable of |
required |
get_attr_node
Get a single node attribute (scalar) or default if missing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
str
|
Node identifier. |
required |
key
|
str
|
Attribute name. |
required |
default
|
Any
|
Value to return if missing. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
|
set_edge_attrs
Upsert pure edge attributes (non-structural) into the edge DF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_id
|
str
|
Edge identifier. |
required |
**attrs
|
Attribute key/value pairs. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If any key is structurally reserved (e.g. |
set_edge_attrs_bulk
Upsert edge attributes in bulk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
updates
|
dict[str, dict] | Iterable[tuple[str, dict]]
|
Mapping or iterable of |
required |
get_attr_edge
Get a single edge attribute (scalar) or default if missing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_id
|
str
|
Edge identifier. |
required |
key
|
str
|
Attribute name. |
required |
default
|
Any
|
Value to return if missing. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
|
set_slice_attrs
Upsert pure slice attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slice_id
|
str
|
Slice identifier. |
required |
**attrs
|
Attribute key/value pairs. Structural keys are ignored. |
{}
|
get_slice_attr
Get a single slice attribute (scalar) or default if missing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slice_id
|
str
|
Slice identifier. |
required |
key
|
str
|
Attribute name. |
required |
default
|
Any
|
Value to return if missing. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
|
set_edge_slice_attrs
Upsert per-slice attributes for a specific edge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slice_id
|
str
|
Slice identifier. |
required |
edge_id
|
str
|
Edge identifier. |
required |
**attrs
|
Attribute key/value pairs. Structural keys are ignored except |
{}
|
edge_slice
Return every attribute one edge carries in one slice.
The level of this store is the pair, so an edge that carries nothing in this slice answers with an empty mapping rather than with the attributes it carries elsewhere.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slice_id
|
str
|
Slice identifier. |
required |
edge_id
|
str
|
Edge identifier. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
|
get_edge_slice_attr
Get a per-slice attribute for an edge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slice_id
|
str
|
Slice identifier. |
required |
edge_id
|
str
|
Edge identifier. |
required |
key
|
str
|
Attribute name. |
required |
default
|
Any
|
Value to return if missing. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
|
set_slice_edge_weight
Set a legacy per-slice weight override for an edge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slice_id
|
str
|
Slice identifier. |
required |
edge_id
|
str
|
Edge identifier. |
required |
weight
|
float
|
Weight override. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the slice or edge does not exist. |
See Also
get_effective_edge_weight
get_effective_edge_weight
Resolve the effective weight for an edge, optionally within a slice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_id
|
str
|
Edge identifier. |
required |
slice
|
str
|
Slice to read the override from. When omitted, the graph's currently active slice is used. Pass an explicit slice ID to override the active-slice resolution. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Effective weight. |
audit_attributes
Audit attribute tables for extra/missing rows and invalid edge-slice pairs.
Returns:
| Type | Description |
|---|---|
dict
|
Summary with keys:
- |
Notes
The node table and the edge table are derived from columns addressed by slot, so a row of either names an element the graph holds and every element the graph holds has one. The first four lists are therefore always empty, and what this still finds is an edge-by-slice row that names a slice or an edge the graph does not hold.
get_edge_attrs
Return the full attribute dict for a single edge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge
|
int | str
|
Edge index or edge ID. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Attribute dictionary for that edge. Empty if not found. |
get_node_attrs
Return the full attribute dict for a single node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
str
|
Node ID. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Attribute dictionary for that node. Empty if not found. |
get_attr_edges
Retrieve edge attributes as a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indexes
|
Iterable[int] | None
|
Edge indices to retrieve. If None, returns all edges. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, dict]
|
Mapping of |
get_attr_nodes
Retrieve node (node) attributes as a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodes
|
Iterable[str] | None
|
Node IDs to retrieve. If None, returns all nodes. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, dict]
|
Mapping of |
get_attr_from_edges
Extract a specific attribute column for all edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Attribute column name to extract. |
required |
default
|
Any
|
Value to use if the column or value is missing. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Mapping of |
get_edges_by_attr
Retrieve all edges where a given attribute equals a specific value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Attribute column name to filter on. |
required |
value
|
Any
|
Value to match. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
Edge IDs where the attribute equals |
get_graph_attributes
Return a shallow copy of the graph-level attributes dictionary.
Returns:
| Type | Description |
|---|---|
dict
|
Shallow copy of global graph metadata. |
Notes
Returned value is a shallow copy to prevent external mutation.
set_edge_slice_attrs_bulk
Upsert edge-slice attributes for a single slice in bulk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slice_id
|
str
|
Slice identifier. |
required |
items
|
Iterable[tuple[str, dict]] | dict[str, dict]
|
Iterable or mapping of |
required |
annnet.core._Annotation.AttributesAccessor
Every attribute of a graph, read and written (G.attrs).
Eight tables, each named for what addresses it — :attr:nodes,
:attr:edges, :attr:slices, :attr:aspects, :attr:layers,
:attr:edge_slices, :attr:node_layers and :attr:elementary_layers —
beside the setters that write them. Each is a property, because a table takes
no arguments. :meth:table is the one call, for naming a backend.
A table here holds what was written. The frames under G.views hold
everything derivable, take filters and joins, and are calls rather than
properties. Five names appear in both namespaces and mean those two different
things.
Attributes
layers
property
Attributes keyed by layer coordinate, as a table.
The whole coordinate across every aspect. One elementary label inside one
aspect is :attr:elementary_layers, which is a different table.
elementary_layers
property
Attributes keyed by elementary layer id, as a table.
One label inside one aspect, addressed by the layer_id that
G.layers.set_elementary_attrs composes from the two.
G.layer_attributes also accepts a table this API cannot address —
one carrying no layer_id — and hands that back exactly as it was
given, because an adapter round-trips it. That promise is the old
property's. Here every table answers in one backend, so a table given in
another is rendered into it.
Functions
table
Return one table by name, optionally in a backend of its own.
The table is the one the property of the same name gives, so the two
cannot answer differently. Naming a backend converts, which costs
something, so it is worth it only for the genuinely mixed case. Set
:attr:backend when every table should answer in the same one. Naming
the backend a table already has — or "auto" — is the table itself
and costs nothing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
One of :data: |
required |
backend
|
(polars, pandas, pyarrow, auto)
|
Defaults to the ambient :attr: |
"polars"
|
Returns:
| Type | Description |
|---|---|
DataFrame - like
|
|