Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement set operations for NodeView and EdgeView #208

Merged
merged 3 commits into from
Nov 2, 2022
Merged

Implement set operations for NodeView and EdgeView #208

merged 3 commits into from
Nov 2, 2022

Conversation

leotrs
Copy link
Collaborator

@leotrs leotrs commented Nov 1, 2022

Since NodeView and EdgeView ultimately inherit from collections.abc.Set, the user should be able to perform set operations on them. As reported in #206 this was not the case. This PR fixes that.

New functionality:

    H = hyperwithattrs
    nodes1 = H.nodes.filterby_attr("color", "blue")
    nodes2 = H.nodes.filterby("degree", 2, "geq")
    assert set(nodes2 - nodes1) == {3, 4}
    assert set(nodes1 - nodes2) == set()
    assert set(nodes1 & nodes2) == {2, 5}
    assert set(nodes1 | nodes2) == {2, 3, 4, 5}
    assert set(nodes1 ^ nodes2) == {3, 4}

Before this PR, any of the set operations would raise an exception.

The fix was easy. Just had to override collections.abc.Set._from_iterable to play well with the rest of the class.

Also added mention of this to the Tutorial.

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@maximelucas
Copy link
Collaborator

Wow nice. The result of nodes2 - nodes1 is still a NodeView right?

@leotrs
Copy link
Collaborator Author

leotrs commented Nov 2, 2022

Wow nice. The result of nodes2 - nodes1 is still a NodeView right?

Yep!

@leotrs leotrs merged commit 743939f into main Nov 2, 2022
@leotrs leotrs deleted the fix-206 branch November 2, 2022 10:52
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.

2 participants