Slices
anet.slices makes and edits slices: named subsets of the edges and nodes, for
example one per condition. A slice can have its own edge weights. See the
slices guide.
annnet.core._Slices.SliceManager
Namespace for all slice operations, exposed as anet.slices.
Attributes
Functions
add
Create a new slice, optionally with its members.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slice_id
|
str
|
|
required |
nodes
|
Iterable[str]
|
Node ids to attach. The three-call opening — create, add nodes, add edges — is what every caller wrote, so it is one call. |
None
|
edges
|
Iterable[str]
|
Edge ids to attach. Their incident nodes come with them, as
:meth: |
None
|
**attributes
|
Any
|
Slice attributes. |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
|
Examples:
remove
Remove a non-default slice and its per-slice attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slice_id
|
str
|
|
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If attempting to remove the internal default slice. |
KeyError
|
If the slice does not exist. |
add_edge_to_slice
Attach an existing edge to a slice (no weight changes).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lid
|
str
|
|
required |
eid
|
str
|
|
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the slice or edge does not exist. |
add_edges
Attach many existing edges to a slice and include their incident nodes.
add_nodes
Attach many existing nodes to a slice.
The bulk counterpart of :meth:add_node_to_slice, and the node-side
mirror of :meth:add_edges. A reader that has just built a membership
set writes it in one call rather than reaching into the registry.
Membership names bare node ids, so a multilayer entity key is reduced to its id the way the rest of the slice API does.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slice_id
|
str | None
|
The slice to extend, or None for the current slice. |
required |
node_ids
|
Iterable[str]
|
Node identifiers. One the graph does not hold is ignored, which is
what :meth: |
required |
attach_edges
Attach every edge the graph holds to a slice, and derive no nodes.
Unlike :meth:add_edges, this keeps an edge that occupies no column, so a
placeholder edge survives a round trip. It also leaves the node
memberships alone. A reader that restores the node memberships from the
file itself needs both, and deriving them again is the dearest loop of a
load.
get_slices_dict
Return the raw slice_id → SliceRecord mapping (distinct from list).
difference
Return the nodes and edges present in one slice but not another.
create_slice_from_operation
Create a new slice from a precomputed membership result.
add_node_to_slice
Attach an existing node to a slice.
Raises:
| Type | Description |
|---|---|
KeyError
|
If the slice or node does not exist. |
union_create
Create a slice from the union of existing slices.
intersect_create
Create a slice from the intersection of existing slices.
difference_create
Create a slice from the difference of two slices.
aggregate
Build a target slice from sources via 'union' or 'intersection'.
edge_presence
edge_presence(
edge_id=None,
source=None,
target=None,
*,
include_default=False,
undirected_match=None
)
Slices containing an edge by id, or by (source, target) endpoint pair.
hyperedge_presence
Slices containing a hyperedge by undirected members or directed head+tail.
conserved_edges
Count edges that appear in at least min_slices slices.
temporal_dynamics
Summarize added and removed members across an ordered slice sequence.
edge_frame
edge_frame(
edges=None,
slices=None,
attrs=None,
*,
pairs=None,
format="wide",
missing=None,
backend=None
)
Read per-slice edge attributes as a table.
The scalar accessor answers for one (slice, edge, name), so reading
an edge by slice by attribute cube meant a Python loop with a default in
it. This is that cube, and it is the shape the question which
interactions carried signal in which condition actually has — one a
source/target/weight frame cannot express at all.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edges
|
Sequence[str]
|
Edge ids. Default: every edge that carries a per-slice attribute. |
None
|
slices
|
Sequence[str]
|
Slice ids. Default: every slice that carries one. |
None
|
attrs
|
Sequence[str]
|
Attribute names. Default: every name present. |
None
|
pairs
|
Mapping[str, tuple[str, str]] | Sequence[tuple[str, str]]
|
Explicit |
None
|
format
|
('wide', 'long')
|
|
"wide"
|
missing
|
Any
|
What a cell with no value holds. Default |
None
|
backend
|
str
|
Dataframe backend. Defaults to the graph's. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame - like
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
compare
Compare the membership of two slices, as a table.
The set operations answer how many; this answers which, and where.
One row per element in either slice, with a status naming the side it
is on — the shape a diff of a prior against a fit wants, and which
callers otherwise built from three set expressions and a loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slice_a
|
str
|
|
required |
slice_b
|
str
|
|
required |
axis
|
('edges', 'nodes')
|
|
"edges"
|
backend
|
str
|
|
None
|
Returns:
| Type | Description |
|---|---|
DataFrame - like
|
Columns |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
KeyError
|
If either slice is unknown. |
Examples:
induce_edges
Attach the edges this slice's nodes already imply.
A slice built by naming nodes holds no edges, so every read of it sees an edgeless graph. Induction is the missing half, and which edges it means is a choice rather than an obvious default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slice_id
|
str
|
|
required |
mode
|
('both', 'any')
|
|
"both"
|
hyper
|
('all', 'skip')
|
Whether a hyperedge may be induced. |
"all"
|
Returns:
| Type | Description |
|---|---|
int
|
The number of edges attached. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
KeyError
|
If the slice is unknown. |
Examples: