Skip to content

Move and generalize the Express graph conversion functions - #116

Merged
wbkboyer merged 6 commits into
graph-algorithms:masterfrom
wheevu:refactor/77-graph-conversions
Oct 21, 2026
Merged

wbkboyer merged 6 commits into
graph-algorithms:masterfrom
wheevu:refactor/77-graph-conversions

Conversation

@wheevu

@wheevu wheevu commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Resolves #77

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • This change requires a documentation update

Changes

  • Adds convert_to_pgraph() and convert_from_pgraph() for NetworkX, edge lists, and dictionaries of dictionaries, sets, or lists.
  • Moves the conversion helpers into planarity_functions.py, preserving the top-level pgraph_graph() and networkx_graph() entry points.
  • Adds 14 tests covering conversions, round trips, isolated vertices, labels, drawing metadata, and errors.

Direct imports of the old helpers from planarity.express.planarity_networkx no longer work, as requested by the move.
Top-level imports remain supported.

The compatibility comments omit the sentence about future docstrings because the new converters already have full docstrings.

Testing

  • Full suite: 81 passed on both Python 3.11.8 and 3.14.7, macOS ARM64.
  • Examples and Sphinx documentation build passed.
  • Python 3.12, 3.13, Windows, and Linux were not tested locally.

The unchanged tests/test_express_api_networkx.py passes before and after:

Before, master at 92e63d1
$ pytest -vv tests/test_express_api_networkx.py

tests/test_express_api_networkx.py::TestPlanarityNetworkX::test_is_planar PASSED [ 16%]
tests/test_express_api_networkx.py::TestPlanarityNetworkX::test_is_planar_unions PASSED [ 33%]
tests/test_express_api_networkx.py::TestPlanarityNetworkX::test_goldner_harary PASSED [ 50%]
tests/test_express_api_networkx.py::TestPlanarityNetworkX::test_kuratowski_k5 PASSED [ 66%]
tests/test_express_api_networkx.py::TestPlanarityNetworkX::test_kuratowski_k5m PASSED [ 83%]
tests/test_express_api_networkx.py::TestPlanarityNetworkX::test_networkx_graph PASSED [100%]

============================== 6 passed in 2.54s ===============================
After
$ pytest -vv tests/test_express_api_networkx.py

tests/test_express_api_networkx.py::TestPlanarityNetworkX::test_is_planar PASSED [ 16%]
tests/test_express_api_networkx.py::TestPlanarityNetworkX::test_is_planar_unions PASSED [ 33%]
tests/test_express_api_networkx.py::TestPlanarityNetworkX::test_goldner_harary PASSED [ 50%]
tests/test_express_api_networkx.py::TestPlanarityNetworkX::test_kuratowski_k5 PASSED [ 66%]
tests/test_express_api_networkx.py::TestPlanarityNetworkX::test_kuratowski_k5m PASSED [ 83%]
tests/test_express_api_networkx.py::TestPlanarityNetworkX::test_networkx_graph PASSED [100%]

============================== 6 passed in 0.13s ===============================

Moves networkx_graph() and pgraph_graph() from planarity_networkx.py to
planarity_functions.py, adds convert_to_pgraph() and
convert_from_pgraph(pgraph, to_type) covering the networkx, edgelist,
dictofdicts, dictofsets, and dictoflists formats, and keeps the original
names working as compatibility entry points.

Resolves graph-algorithms#77
convert_from_pgraph() forwards the DrawPlanar vertex and edge info into
the networkx.Graph, matching networkx_graph()'s behavior before the
move. The existing tests compare two empty-attribute graphs, so they
cannot catch a dropped include_drawplanar flag.
@wbkboyer
wbkboyer self-requested a review October 21, 2026 00:03
* fixed intersphinx syntax and description of implementation details in `ascii()` docstring (missed in prior passes),
* added `# pylint: disable=import-outside-toplevel` to disable `pylint` complaints in `kuratowski_subgraph()` and `convert_from_pgraph()`
* updated `ImportError` exception handling to re-raise `networkx_import_error` in `kuratowski_subgraph()` and `convert_from_pgraph()`,
* restored docstrings for `pgraph_graph() and `networkx_graph()` to include deprecation warnings with instructions for new functions to use,
* added `warnings.warn(category=DeprecationWarning)` to `pgraph_graph() and `networkx_graph()` functions.
Comment thread tests/test_express_api_conversions.py

@wbkboyer wbkboyer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looking great so far, Josh (@wheevu)! In addition to the changes requested, could you locally run

pylint --disable="invalid-name,missing-class-docstring,missing-function-docstring,missing-module-docstring,import-error" tests/test_express_api_conversions.py

And resolve the warnings? For the global-statement, undefined-variable, and import-outside-toplevel, if there's no better way to handle testing for networkx in the test environment and skipping the test if it's not present, then you can # pylint: disable=... on those lines!

Comment thread tests/test_express_api_conversions.py
Comment thread tests/test_express_api_conversions.py Outdated
Comment thread tests/test_express_api_conversions.py
@wheevu

wheevu commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, Wanda @wbkboyer! 😄 I addressed your comments in 3caf406: added dictionary-of-lists coverage for the isolated vertex, corrected cls, and resolved the Pylint warnings. Your Pylint command is clean, and all 132 tests pass locally on Python 3.11 and 3.14.

@wbkboyer
wbkboyer self-requested a review October 21, 2026 18:10
…cit dependencies such as networkx, matplotlib, or PIL (pillow) are installed in the test environment.

`@pytest.mark.skipif()` can be used to decorate individual tests or a class of tests so that these skips appear in the `pytest -vvv` output. The alternative, `pytest.importorskip()`,  will cause the entire test module to be skipped, and to only report the skips during the *collection* phase rather than when running *only if* you run `pytest` using flags `-rs`)
@wbkboyer

Copy link
Copy Markdown
Member

Thanks, Wanda @wbkboyer! 😄 I addressed your comments in 3caf406: added dictionary-of-lists coverage for the isolated vertex, corrected cls, and resolved the Pylint warnings. Your Pylint command is clean, and all 132 tests pass locally on Python 3.11 and 3.14.

Right on, thank you for addressing those issues, @wheevu 🎉 I ended up making some additional changes (21ea12) to fix some of the leftover pylint warnings: I use the @pytest.mark.skipif() to selectively condition test execution on a variable that's set based on the successful import of dependencies networkx, matplotlib, pillow (is a dependency of matplotlib, so gets installed when we pip install matplotlib), or sphinx 💪🏼 I'll take one final look, but I think this is ready to rock at this point! Thank you again!

@wbkboyer wbkboyer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is looking good; thanks again, @wheevu ! 🎉

@wbkboyer
wbkboyer merged commit 40ef48a into graph-algorithms:master Oct 21, 2026
4 checks passed
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.

Express API: Graph Conversions

2 participants