Skip to content

fix: Adjacency() makes self-loops from the diagonal for both graph kinds - #32

Merged
petercorke merged 3 commits into
mainfrom
fix/adjacency-diagonal-loops
Oct 11, 2026
Merged

petercorke merged 3 commits into
mainfrom
fix/adjacency-diagonal-loops

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Stacked on the vertex_class/edge_class PR (feat/graph-vertex-edge-class): the base of this PR is that branch, so the diff shows only this change.

Summary

DGraph.Adjacency() raised ValueError: loops in graph not supported on a non-zero diagonal, while UGraph.Adjacency() silently dropped it (it only read the strict upper triangle). Everything else (connect, add_edge) permits self-loops, so the factory was the one place that refused or lost them.

A non-zero diagonal element A[i, i] is now a self-loop on vertex i, with the element as its cost, for both graph kinds.

Behavior change

DGraph.Adjacency() no longer raises for a diagonal. If rejecting loops there is preferred, it is a one-line change, but then connect() should reject them too for consistency.

Notes

  • Elements are costs, not counts, so parallel edges still cannot be created from a matrix; this is now stated in the docstring.
  • The :raises: list is corrected to what actually raises.

Tests

tests/test_adjacency_loops.py, 10 tests across both graph kinds.

🤖 Generated with Claude Code

petercorke and others added 2 commits October 11, 2026 11:11
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
DGraph.Adjacency() raised ValueError('loops in graph not supported') on a
non-zero diagonal while UGraph.Adjacency() silently dropped it, and every
other entry point (connect, add_edge) permits self-loops. The diagonal is
now a self-loop, with the element as its cost, for both.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codacy-production

codacy-production Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 10 complexity · 0 duplication

Metric Results
Complexity 10
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Base automatically changed from feat/graph-vertex-edge-class to main October 11, 2026 04:11
@petercorke
petercorke merged commit 7c68cab into main Oct 11, 2026
12 checks passed
@petercorke
petercorke deleted the fix/adjacency-diagonal-loops branch October 11, 2026 04:13
@codecov

codecov Bot commented Oct 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.76%. Comparing base (3b203d9) to head (96ba4d6).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #32      +/-   ##
==========================================
+ Coverage   90.31%   90.76%   +0.45%     
==========================================
  Files           2        2              
  Lines         847      845       -2     
==========================================
+ Hits          765      767       +2     
+ Misses         82       78       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant