Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BEHAVIOR: remove topology edge number check #249

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions src/qrules/topology.py
Original file line number Diff line number Diff line change
@@ -252,33 +252,23 @@

def __attrs_post_init__(self) -> None:
self.__verify()
incoming = sorted(
incoming = {
edge_id
for edge_id, edge in self.edges.items()
if edge.originating_node_id is None
)
outgoing = sorted(
}
outgoing = {
edge_id
for edge_id, edge in self.edges.items()
if edge.ending_node_id is None
)
inter = sorted(set(self.edges) - set(incoming) - set(outgoing))
expected = list(range(-len(incoming), 0))
if sorted(incoming) != expected:
msg = f"Incoming edge IDs should be {expected}, not {incoming}."
raise ValueError(msg)
n_out = len(outgoing)
expected = list(range(n_out))
if sorted(outgoing) != expected:
msg = f"Outgoing edge IDs should be {expected}, not {outgoing}."
raise ValueError(msg)
expected = list(range(n_out, n_out + len(inter)))
if sorted(inter) != expected:
msg = f"Intermediate edge IDs should be {expected}."
}
if incoming & outgoing:
msg = "Topology has both incoming and outgoing edges. This is not allowed."

Check warning on line 266 in src/qrules/topology.py

Codecov / codecov/patch

src/qrules/topology.py#L266

Added line #L266 was not covered by tests
raise ValueError(msg)
intermediate = set(self.edges) - incoming - outgoing
object.__setattr__(self, "incoming_edge_ids", frozenset(incoming))
object.__setattr__(self, "outgoing_edge_ids", frozenset(outgoing))
object.__setattr__(self, "intermediate_edge_ids", frozenset(inter))
object.__setattr__(self, "intermediate_edge_ids", frozenset(intermediate))

def __verify(self) -> None:
"""Verify if there are no dangling edges or nodes."""