Skip to content

Conversation

eumiro
Copy link
Contributor

@eumiro eumiro commented Mar 28, 2025

I realized the ancestors and descendants raise an IndexError if the provided node is not present in the directed graph. On the other hand predecessors and successors, which are quite similar methods, just return an empty list.

I do not want to introduce a breaking change, so I just added a test pair to make sure this persists.

Also for the formatting, I discovered the docs website was using Furo which offers some nice details to distinguish different parts of a method documentation. Before we have lots of docs, we'll have to find some useful and decent style.

@coveralls
Copy link

coveralls commented Mar 28, 2025

Pull Request Test Coverage Report for Build 14142482732

Details

  • 12 of 12 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.001%) to 95.33%

Totals Coverage Status
Change from base Build 14141623865: 0.001%
Covered Lines: 18495
Relevant Lines: 19401

💛 - Coveralls

Copy link
Collaborator

@IvanIsCoding IvanIsCoding left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for documenting the current behaviors.

I am curious about what ..seealso is going to look on the docs, but it is a Sphinx directive and it is pretty appropriate for our situation. Our theme is patched but it should support it.

I left a minor Rust comment

src/digraph.rs Outdated
@@ -705,9 +715,8 @@ impl PyDiGraph {
let mut predec: Vec<&PyObject> = Vec::new();
let mut used_indices: HashSet<NodeIndex> = HashSet::new();
for pred in parents {
if !used_indices.contains(&pred) {
if used_indices.insert(pred) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, let's rewrite this to use this API with a match statement: https://docs.rs/hashbrown/latest/hashbrown/struct.HashSet.html#method.entry

That way the behavior is clearer. Your code and the existing codes are equivalent, your code saves a lookup but it is not obvious.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed both predecessors/successors syntax.

Since the usage of this syntax is not consistent across the whole project, I'm going to consolidate it elsewhere.

@IvanIsCoding IvanIsCoding added this pull request to the merge queue Mar 29, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 29, 2025
@IvanIsCoding IvanIsCoding added this pull request to the merge queue Mar 29, 2025
Merged via the queue into Qiskit:main with commit d7b3f4f Mar 29, 2025
31 checks passed
@eumiro
Copy link
Contributor Author

eumiro commented Mar 29, 2025

I am curious about what ..seealso is going to look on the docs, but it is a Sphinx directive and it is pretty appropriate for our situation. Our theme is patched but it should support it.

It looks good, but the link is not rendered, so it's not useful.

@eumiro eumiro deleted the pred-succ-anc-desc branch March 29, 2025 18:57
SILIZ4 pushed a commit to SILIZ4/rustworkx that referenced this pull request Jul 4, 2025
* Enhance docs and tests for pred/succ/anc/desc

* Use match pattern in predecessors/successors
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.

3 participants