Skip to content

Fix to_pyg graph attribute mutation#143

Open
pragnyanramtha wants to merge 1 commit into
mllam:mainfrom
pragnyanramtha:fix-139-to-pyg-preserve-graph
Open

Fix to_pyg graph attribute mutation#143
pragnyanramtha wants to merge 1 commit into
mllam:mainfrom
pragnyanramtha:fix-139-to-pyg-preserve-graph

Conversation

@pragnyanramtha

Copy link
Copy Markdown

Summary

  • copy the input graph before pruning node attributes for PyG export
  • keep exported PyG graphs limited to requested node features
  • add a regression test proving the caller graph remains unchanged

Fixes #139.

Validation

  • PYTHONPATH=src python -m pytest tests/test_save.py::test_to_pyg_does_not_mutate_node_attributes -q
  • PYTHONPATH=src python -m pytest tests/test_save.py -q
  • python -m black --check src/weather_model_graphs/save.py tests/test_save.py
  • python -m isort --check-only src/weather_model_graphs/save.py tests/test_save.py
  • python -m flake8 src/weather_model_graphs/save.py tests/test_save.py
  • git diff --check

Copilot AI review requested due to automatic review settings May 13, 2026 21:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes weather_model_graphs.save.to_pyg() mutating the caller’s NetworkX graph by pruning node attributes on a copied graph prior to PyTorch Geometric conversion, and adds a regression test to prevent reintroduction.

Changes:

  • Copy the input graph inside to_pyg() and prune node attributes on the copy (not the caller-owned graph).
  • Ensure downstream conversion/splitting logic uses the copied/pruned graph consistently.
  • Add a regression test that asserts the input graph’s node attributes remain unchanged while the exported/converted graph excludes unrequested attributes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/weather_model_graphs/save.py Avoids mutating the input graph by copying before pruning node attributes and exporting.
tests/test_save.py Adds a regression test verifying to_pyg() does not delete node attributes on the caller graph.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

save.to_pyg() mutates the input graph by deleting node attributes in place

2 participants