Skip to content

fix: graph[x] returned None for NumPy integers and other types - #28

Merged
petercorke merged 3 commits into
mainfrom
fix/getitem-type-check
Oct 11, 2026
Merged

petercorke merged 3 commits into
mainfrom
fix/getitem-type-check

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

graph[x] fell off the end of __getitem__ and returned None for anything that wasn't a Python int, str or vertex.

The consequential case is NumPy integers: g[np.argmin(d)] quietly gave None, which then fails somewhere far away.

Change

  • np.integer accepted alongside int.
  • Any other type raises TypeError.
  • The IndexError / KeyError / TypeError behavior is documented in the docstring (which also had a mis-formatted bullet list).

Tests

tests/test_getitem.py: int, negative int, np.int64, np.argmin result, name, vertex, unknown name, out-of-range, and a set of wrong types.

🤖 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>
__getitem__ fell off the end and returned None for anything that was not
a Python int, str or vertex -- including np.int64, so g[np.argmin(d)]
quietly gave None. NumPy integers are now accepted, and any other type
raises TypeError. Exceptions are documented.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@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 87.60%. Comparing base (b6e799a) to head (c30f1f1).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #28      +/-   ##
==========================================
+ Coverage   87.59%   87.60%   +0.01%     
==========================================
  Files           2        2              
  Lines         814      815       +1     
==========================================
+ Hits          713      714       +1     
  Misses        101      101              

☔ 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.

@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 11 complexity · 2 duplication

Metric Results
Complexity 11
Duplication 2

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.

@petercorke
petercorke merged commit 0566a68 into main Oct 11, 2026
12 checks passed
@petercorke
petercorke deleted the fix/getitem-type-check branch October 11, 2026 04:06
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