Skip to content

Fix for issue #7645: Do not preserve 'cw' and 'ccw' attributes in PlanarEmbedding.to_undirected() - #7750

Merged
rossbar merged 13 commits into
networkx:mainfrom
Schwarf:bugfix-for-issue-7645
Jan 19, 2025
Merged

rossbar merged 13 commits into
networkx:mainfrom
Schwarf:bugfix-for-issue-7645

Conversation

@Schwarf

@Schwarf Schwarf commented Dec 1, 2024 •

Copy link
Copy Markdown
Contributor

I propose this fix for issue #7645. The changes ensure that the 'cw' and 'ccw' attributes are not preserved for both graphs and multi-graphs in the result of PlanarEmbedding.to_undirected().

I have included tests to verify that the issue is resolved.

I would be grateful for any feedback or suggestions to improve this PR. I am more than happy to incorporate any necessary changes based on the review. Thank you for your time and guidance!

Fixes #7645

@Schwarf Schwarf changed the title Fix for issue #7645: Preserve 'cw' and 'ccw' attributes in PlanarEmbedding.to_undirected() Fix for issue #7645: Do not preserve 'cw' and 'ccw' attributes in PlanarEmbedding.to_undirected() Dec 1, 2024
@dschult

dschult commented Dec 1, 2024

Copy link
Copy Markdown
Member

Thank you for putting this together @Schwarf

These changes are made to the base class methods. But they should only apply for the PlanarEmbedding subclass. That is, someone who happens to create edge attributes named 'cw' will lose those attributes when they haven't ever used the planarity code. Can you move these changes to methods in the PlanarEmbedding class?

@Schwarf

Schwarf commented Dec 1, 2024 •

Copy link
Copy Markdown
Contributor Author

Hi @dschult ,
thank you for your feedback. I will have a look.
Best regards
Andreas

@Schwarf

Schwarf commented Dec 1, 2024

Copy link
Copy Markdown
Contributor Author

My update has now added an overload of the to_undirected() method to the class PlanarEmbedding. I have removed the parameter reciprocal and corresponding functionality, because in my understanding its not relevant for planarity. Am I correct?
For the as_view parameter I am actually not sure if its useful or not. I left the parameter but did not write a test (yet), until ist confirmed that this functionality is wanted in class PlanarEmbedding.

Thank you for your support. Looking forward to your feedback.

@rossbar rossbar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

My update has now added an overload of the to_undirected() method to the class PlanarEmbedding. I have removed the parameter reciprocal and corresponding functionality, because in my understanding its not relevant for planarity. Am I correct?
For the as_view parameter I am actually not sure if its useful or not. I left the parameter but did not write a test (yet), until ist confirmed that this functionality is wanted in class PlanarEmbedding.

My immediate reaction is that both as_view and reciprocal should be supported, if for no other reason than to maintain consistency with the API of the base class.

Re: as_view - AFAIK there's no (builtin) way to filter edge attributes in graph views, so an as_view=True will result in a graph view that still has the cw and ccw attributes on the edges. My current opinion is that this shouldn't be a blocker for now.

Re: reciprocal - I think it's a worthwhile feature to keep, even if it's not directly relevant for any sort of planarity analyses.

@Schwarf
Schwarf force-pushed the bugfix-for-issue-7645 branch from ee520eb to fee3140 Compare December 6, 2024 13:40
@Schwarf
Schwarf requested a review from rossbar December 6, 2024 14:48

@dschult dschult 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.

Thanks for putting it into the PlanarEmbedding class.
The code looks fine. I probably would have made the as_view and reciprocal raise exceptions if used, but this is fine too. (the concept of views of planar embeddings seems strange to me; and all valid embeddings should have half-edges in both directions for every edge so reciprocal would only be needed for invalid embeddings.)

My suggestions are about the docs -- mostly about reference to "the original graph" being shifted to "the PlanarEmbedding" and related shifts away from the notation that the planar graph is some sort of directed graph when it is actually a representation of an undirected graph that happens to use a DiGraph super-class. You can change these suggestions by using local changes/commits. The github "add suggestion" feature makes it easy for me to suggest, but not as easy for you to adapt that to what you want. So use whatever you need to.

Comment thread networkx/algorithms/planarity.py Resolved
Comment thread networkx/algorithms/planarity.py Resolved
Comment thread networkx/algorithms/planarity.py Resolved
Comment thread networkx/algorithms/planarity.py Resolved
Comment thread networkx/algorithms/planarity.py Resolved
Comment thread networkx/algorithms/planarity.py Resolved
Comment thread networkx/algorithms/planarity.py Resolved
@Schwarf

Schwarf commented Dec 7, 2024 •

Copy link
Copy Markdown
Contributor Author

Thank you for the detailed feedback! I appreciate your points, especially regarding the wording in the documentation. You’re absolutely correct that my description of the method was misleading, and I will make sure to update it to reflect the correct terminology and intent.

I also think your suggestion to raise exceptions for as_view and reciprocal is an excellent idea. Providing immediate feedback to users about the unusual nature of the PlanarEmbedding graph is a great way to improve usability and prevent potential confusion. I’ll incorporate this change into the method as well.

@Schwarf
Schwarf requested a review from dschult December 7, 2024 08:45

@dschult dschult 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.

Thanks for these changes. I only have minor tweaks here.

Comment thread networkx/algorithms/planarity.py Resolved
Comment thread networkx/algorithms/planarity.py Resolved
Comment thread networkx/algorithms/planarity.py Resolved
Schwarf and others added 3 commits December 12, 2024 17:31
Update docu

Co-authored-by: Dan Schult <[email protected]>
Update docu

Co-authored-by: Dan Schult <[email protected]>
Remove unreachable legacy code

Co-authored-by: Dan Schult <[email protected]>

@dschult dschult 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.

Looks good to me!
Thanks!!

@Schwarf

Schwarf commented Dec 19, 2024

Copy link
Copy Markdown
Contributor Author

Hi @dschult @rossbar ,

I hope you're doing well. I wanted to clarify the process regarding issue #7645 linked to this PR. Should I close the issue manually once the PR is merged, or is it handled automatically/by the maintainers?

Thanks for your guidance, and Happy Holidays.

Best regards,
Andreas

@dschult

dschult commented Dec 19, 2024

Copy link
Copy Markdown
Member

The automated close occurs if you put special text into the PR posting that connects the PR to the issue, or if someone has connected this PR to the issue in the Development section on the right sidebar of this page. Those are the two ways I know of.

To use text to connect the PR to the issue, put Fixes #7645 in the original post. I have edited the initial post to include that now. I think it might also work by putting it into the commit description. And there are other syntaxes like Closes #7645 that work too.
See details in the github docs

@rossbar rossbar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM,thanks @Schwarf and @dschult !

@rossbar
rossbar merged commit 6dc07d7 into networkx:main Jan 19, 2025
@jarrodmillman jarrodmillman added this to the 3.5 milestone May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

PlanarEmbedding.to_undirected() result in a Graph whose edges keep the 'cw' and 'ccw' attributes of one of the half-edges.

4 participants