Skip to content

Conversation

@rochSmets
Copy link
Contributor

When using finest_part_data of a particle hierarchy (for example in a dist_plot with finest=True) we need to iterate through the patches, hence know their names. Then, these names was taken from the first patch_data, of index 0. But this one could eventually be empty, hence not able to provide these names.

In this version, we hence iterate on all the patches of level 0, and then get the index of the first one that is not empty. This index is then used to get the keys of the patch_data dict, as it is then the first one to know them.

With this fix, we should then be able to make the dist_plot of a set of particles containing empty patch(es).

@coderabbitai
Copy link

coderabbitai bot commented Jan 9, 2026

📝 Walkthrough

Walkthrough

finest_part_data now scans level-0 patches to find the first patch with non-empty patch_datas, uses that patch (index i_ref) to initialize aPatch and build finalParticles, and raises ValueError("This particle hierarchy seems empty !") if none are found.

Changes

Cohort / File(s) Summary
Patch initialization logic
pyphare/pyphare/pharesee/hierarchy/hierarchy.py
Updated finest_part_data to locate the first non-empty level-0 patch and use its index (i_ref) for initialization instead of unconditionally using patches[0]. Adds explicit ValueError when no non-empty patch exists.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: ensuring the reference patch used in finest_part_data is not empty, which matches the core modification.
Description check ✅ Passed The description clearly explains the problem, the solution, and the expected effect, all directly related to the changeset in finest_part_data.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings


📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 70141be and f8da4a2.

📒 Files selected for processing (1)
  • pyphare/pyphare/pharesee/hierarchy/hierarchy.py
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-10-18T13:23:32.074Z
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 910
File: pyphare/pyphare/pharesee/hierarchy/hierarchy_utils.py:7-7
Timestamp: 2024-10-18T13:23:32.074Z
Learning: In the `pyphare.pharesee.hierarchy` module, importing `PatchHierarchy` and `format_timestamp` from `hierarchy.py` into `hierarchy_utils.py` is acceptable as long as `hierarchy.py` does not import `hierarchy_utils.py`, thereby avoiding a cyclic import.

Applied to files:

  • pyphare/pyphare/pharesee/hierarchy/hierarchy.py
🪛 GitHub Check: CodeQL
pyphare/pyphare/pharesee/hierarchy/hierarchy.py

[notice] 632-632: Testing equality to None
Testing for None should use the 'is' operator.

🪛 Ruff (0.14.11)
pyphare/pyphare/pharesee/hierarchy/hierarchy.py

629-629: Loop control variable i_ref not used within loop body

(B007)


632-632: Comparison to None should be cond is None

Replace with cond is None

(E711)


633-633: Avoid specifying long messages outside the exception class

(TRY003)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Analyze (cpp)
  • GitHub Check: Analyze (python)
  • GitHub Check: build (ubuntu-latest, gcc)
  • GitHub Check: build (ubuntu-latest, clang)
  • GitHub Check: build (macos-latest)
  • GitHub Check: build (macos-14)

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8cd180f and 70141be.

📒 Files selected for processing (1)
  • pyphare/pyphare/pharesee/hierarchy/hierarchy.py
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 910
File: pyphare/pyphare/pharesee/hierarchy/hierarchy_utils.py:7-7
Timestamp: 2024-10-18T13:23:32.074Z
Learning: In the `pyphare.pharesee.hierarchy` module, importing `PatchHierarchy` and `format_timestamp` from `hierarchy.py` into `hierarchy_utils.py` is acceptable as long as `hierarchy.py` does not import `hierarchy_utils.py`, thereby avoiding a cyclic import.
📚 Learning: 2024-10-18T13:23:32.074Z
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 910
File: pyphare/pyphare/pharesee/hierarchy/hierarchy_utils.py:7-7
Timestamp: 2024-10-18T13:23:32.074Z
Learning: In the `pyphare.pharesee.hierarchy` module, importing `PatchHierarchy` and `format_timestamp` from `hierarchy.py` into `hierarchy_utils.py` is acceptable as long as `hierarchy.py` does not import `hierarchy_utils.py`, thereby avoiding a cyclic import.

Applied to files:

  • pyphare/pyphare/pharesee/hierarchy/hierarchy.py
🪛 Ruff (0.14.10)
pyphare/pyphare/pharesee/hierarchy/hierarchy.py

628-628: Loop control variable i_ref not used within loop body

(B007)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: build (macos-latest)
  • GitHub Check: build (macos-14)
  • GitHub Check: Analyze (cpp)
  • GitHub Check: build (ubuntu-latest, gcc)
  • GitHub Check: build (ubuntu-latest, clang)

for i_ref, p in enumerate(hierarchy.level(0, time=time).patches):
if p.patch_datas.__len__()!=0:
break
if i_ref == None:

Check notice

Code scanning / CodeQL

Testing equality to None Note

Testing for None should use the 'is' operator.
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.

1 participant