Skip to content

fix(graph): accept float props in add_node/add_edge and validate before writing (#358) - #360

Open
Chaithanya123123 wants to merge 1 commit into
codeforstartups:developmentfrom
Chaithanya123123:fix/graph-float-props
Open

Chaithanya123123 wants to merge 1 commit into
codeforstartups:developmentfrom
Chaithanya123123:fix/graph-float-props

Conversation

@Chaithanya123123

Copy link
Copy Markdown

Description

GraphStore.add_node() and GraphStore.add_edge() raised TypeError for float props such as a confidence score, while import_graph() stored the same props. They now convert props the same way import_graph() does, so floats are stored as Decimal.

add_edge() also created both endpoint nodes before an invalid edge was rejected. It now validates the weight and props first, so a failed call writes nothing.

Related issue

Fixes #358

Changes

  • add_node() and add_edge() convert props with the existing _properties() helper used by import_graph(). The caller's dict is not modified.
  • New _edge_weight() helper, shared by add_edge() and import_graph(), rejects non-finite weights such as nan and inf.
  • add_edge() builds and validates the edge before creating its endpoints.
  • Tests: float props on nodes and edges, identical results for incremental and bulk writes, and invalid props or weights leaving no nodes behind.

Testing

  • Tests pass locally: full suite 1,217 passed, 2 skipped (Python 3.12, Windows); graph and dashboard tests rerun after rebasing onto development.
  • Ruff checks pass (ruff check src benchmarks); mypy passes.
  • Documentation updated, if applicable: not needed, no public API change.

Checklist

  • My changes are focused and relevant to this pull request.
  • I have added or updated tests where appropriate.
  • I have reviewed my changes for unrelated modifications.
  • I have updated documentation where necessary.

🤖 Generated with Claude Code

…re writing (codeforstartups#358)

add_node() and add_edge() now convert props the same way import_graph() does, so floats such as confidence scores are stored as Decimal instead of raising TypeError. add_edge() validates its weight and props before creating either endpoint, so a rejected edge no longer leaves orphan nodes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

[Bug]: graph add_node() / add_edge() crash on float props, and a failed add_edge() leaves orphan nodes

1 participant