Skip to content

[TEST][pyOpenMS] Output params (§2): pin get_peaks / get2DPeakData* return-value wrapping (#9460) - #9608

Merged
timosachsenberg merged 3 commits into
developfrom
9460-tests-section2-output-params
Jul 15, 2026
Merged

timosachsenberg merged 3 commits into
developfrom
9460-tests-section2-output-params

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Context

Closes the §2 (pyOpenMS nanobind rewrite) [AUTO] output-parameter gap (L94) of the OpenMS 3.6.0 pre-release testing plan (#9460). Tests only.

The nanobind rewrite re-wrapped the ~50 mutable-ref output params to return their results. test_output_parameters.py already covers most of them, but not the numpy peak-data getters the issue names explicitly — this adds them.

Changes (in test_output_parameters.py)

  • TestMSSpectrumGetPeaks — MSSpectrum.get_peaks() returns the (mz, intensity) arrays (float64 / float32) with correct values; plus an empty-spectrum case.
  • TestMSExperimentGet2DPeakData — MSExperiment.get2DPeakData / get2DPeakDataLong / get2DPeakDataIM return the (rt, mz, intensity[, ion_mobility]) arrays the C++ fills by reference: non-empty for an in-range query, get2DPeakDataLong keeps rt/mz at float64, get2DPeakDataIM returns the 4-tuple.

numpy is importorskip-optional.

Test plan

cd /tmp && PYTHONPATH=$REPO/OpenMS-build/pyOpenMS python3 -m pytest $REPO/src/pyOpenMS/tests/ \
  -k "MSSpectrumGetPeaks or MSExperimentGet2DPeakData" -v

→ 5 passed; no regressions in the rest of test_output_parameters.py.

Part of #9460 (§2).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added regression tests to strengthen peak data retrieval validation and ensure reliability.
    • Tests verify that peak data operations return properly formatted results with correct data types and dimensions.
    • Enhanced coverage for various spectrum states and multi-dimensional data variants with appropriate precision handling.

…eturn-value wrapping (#9460)

Close the §2 (pyOpenMS nanobind rewrite) [AUTO] output-parameter gap (L94). The mutable-ref output
params were wrapped to RETURN their results; test_output_parameters.py already covered ~50 such
methods but not the numpy peak-data getters the issue names explicitly. Tests only.

- TestMSSpectrumGetPeaks: MSSpectrum.get_peaks() returns the (mz, intensity) arrays (float64 / float32),
  with correct values and an empty-spectrum case.
- TestMSExperimentGet2DPeakData: MSExperiment.get2DPeakData / get2DPeakDataLong / get2DPeakDataIM return
  the (rt, mz, intensity[, ion_mobility]) arrays the C++ fills by reference -- non-empty for an in-range
  query, get2DPeakDataLong keeps rt/mz at float64, get2DPeakDataIM returns the 4-tuple.

numpy is importorskip-optional. Verified with the built nanobind bindings (5 passed).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@timosachsenberg timosachsenberg mentioned this pull request Jun 17, 2026
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds 104 lines of regression tests to test_output_parameters.py. Two new test classes cover MSSpectrum.get_peaks() (tuple cardinality, NumPy dtypes, empty-spectrum edge case) and MSExperiment.get2DPeakData, get2DPeakDataLong, and get2DPeakDataIM (array count, float64 precision for the Long variant, and equal-length parallel arrays for the IM variant).

Changes

Output parameter binding regression tests

Layer / File(s) Summary
MSSpectrum.get_peaks tuple and dtype assertions
src/pyOpenMS/tests/unittests/test_output_parameters.py
TestMSSpectrumGetPeaks asserts get_peaks() returns a 2-tuple of NumPy arrays with correct lengths for a populated spectrum and for an empty spectrum.
MSExperiment 2D peak data — cardinality, precision, and IM
src/pyOpenMS/tests/unittests/test_output_parameters.py
TestMSExperimentGet2DPeakData adds a _make_exp() helper and three test methods: get2DPeakData returns 3 arrays, get2DPeakDataLong returns float64 rt/mz and float32 intensity, and get2DPeakDataIM returns 4 equal-length arrays.

Possibly related PRs

  • OpenMS/OpenMS#9544: Extends tests for the same pyOpenMS getters (MSSpectrum.get_peaks, MSExperiment.get2DPeakData, get2DPeakDataLong), validating tuple-of-arrays contracts from a buffer-lifetime-across-GC perspective rather than the dtype/cardinality angle covered here.

Poem

🐇 Hop, hop, through the peaks I go,
Checking tuples, float64 in a row,
mz and intensity, side by side,
No silent discards where outputs hide,
The arrays are correct — I have verified!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and specifically references the main change: adding regression tests for C++ output parameters, specifically pinning the return-value wrapping of get_peaks and get2DPeakData* methods.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 9460-tests-section2-output-params

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.

@coderabbitai coderabbitai Bot 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/pyOpenMS/tests/unittests/test_output_parameters.py (1)

745-755: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Strengthen IM in-range assertions to prevent false positives.

This test currently passes even if get2DPeakDataIM(...) returns four empty arrays for an in-range query. Add a non-empty expectation (and ideally exact expected count) so it actually guards the output-parameter return contract.

Suggested patch
     def test_get2DPeakDataIM_returns_quadruple(self):
         pytest.importorskip("numpy")
         exp = self._make_exp()

         result = exp.get2DPeakDataIM(50.0, 250.0, 100.0, 300.0, 1)
         assert isinstance(result, tuple), f"Expected tuple, got {type(result)}"
         assert len(result) == 4  # rt, mz, intensity, ion_mobility
         rt, mz, intensity, ion_mobility = result
         # the four parallel arrays are all populated to the same length (output not dropped)
         assert len(rt) == len(mz) == len(intensity) == len(ion_mobility)
+        assert len(rt) == 4
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/pyOpenMS/tests/unittests/test_output_parameters.py` around lines 745 -
755, The test for the get2DPeakDataIM method does not verify that the returned
arrays are actually populated with data. Currently it only checks that all four
arrays (rt, mz, intensity, ion_mobility) have the same length, which could pass
even if all arrays are empty. Add an assertion to ensure that the returned
arrays are non-empty (len(rt) > 0) and if possible, verify the exact expected
count of elements based on the query parameters passed to get2DPeakDataIM (50.0,
250.0, 100.0, 300.0, 1) to properly guard the output-parameter return contract.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/pyOpenMS/tests/unittests/test_output_parameters.py`:
- Around line 745-755: The test for the get2DPeakDataIM method does not verify
that the returned arrays are actually populated with data. Currently it only
checks that all four arrays (rt, mz, intensity, ion_mobility) have the same
length, which could pass even if all arrays are empty. Add an assertion to
ensure that the returned arrays are non-empty (len(rt) > 0) and if possible,
verify the exact expected count of elements based on the query parameters passed
to get2DPeakDataIM (50.0, 250.0, 100.0, 300.0, 1) to properly guard the
output-parameter return contract.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7bc1d1ba-dca0-460a-b996-3196d5f96b07

📥 Commits

Reviewing files that changed from the base of the PR and between 9a206aa and 22a5486.

📒 Files selected for processing (1)
  • src/pyOpenMS/tests/unittests/test_output_parameters.py

Copy link
Copy Markdown
Contributor Author

Adversarial review result: no blocking issue found in this pass.

Required source cleanup before merge: the added Python test docstrings include tracker references. Please remove those references from source comments/docstrings and keep the text focused on the output-parameter wrapping contract. I did not run the tests locally.

@timosachsenberg

Copy link
Copy Markdown
Contributor Author

@copilot Required source cleanup before merge: the added Python test docstrings include tracker references. Please remove those references from source comments/docstrings and keep the text focused on the output-parameter wrapping contract. I did not run the tests locally.

Copilot AI commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

@copilot Required source cleanup before merge: the added Python test docstrings include tracker references. Please remove those references from source comments/docstrings and keep the text focused on ...

Addressed in commit 4a0877a: removed tracker references from the added test docstrings and kept the text focused on the output-parameter wrapping contract.

@timosachsenberg
timosachsenberg merged commit dcc8844 into develop Jul 15, 2026
41 checks passed
@timosachsenberg
timosachsenberg deleted the 9460-tests-section2-output-params branch July 15, 2026 04:19
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