Repository navigation
[pyOpenMS][TEST] Prove numpy peak-data getters survive owner GC (#9460) - #9544
timosachsenberg merged 1 commit into
Conversation
…MS#9460) MSSpectrum.get_peaks() and MSExperiment.get2DPeakData()/get2DPeakDataLong() return their peak data as numpy arrays whose buffer is owned by an nb::capsule (delete[]), independent of the C++ source. They are safe by construction today; this pins that so a future change to a view-returning implementation (sharing the source buffer) is caught. test_spectrum_zerocopy.py already covers get_peaks_struct(); these cover the get_peaks()/get2DPeakData() getters named in the issue. Each test snapshots the arrays WHILE the source is alive, then `del`s it + gc.collect(), then asserts the arrays are byte-identical -- snapshot-before-delete keeps it non-vacuous. Complements the Arrow zero-copy lifetime test. Verified against the built nanobind bindings (3 passed). Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughA new pytest module is added that verifies the buffer lifetime contract for nanobind numpy wrappers: Changesnumpy getter buffer lifetime tests
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
@timosachsenberg The following names might be missing from the
Please consider applying the following patch: --- AUTHORS 2026-06-15 18:15:54.170206220 +0000
+++ AUTHORS.new 2026-06-15 18:15:59.553664334 +0000
@@ -23,8 +23,8 @@
- Chirag Dave
- Chris Bauer
- Chris Bielow
- - Christie Mathews
- Christian Ehrlich
+ - Christie Mathews
- Clemens Groepl
- Cornelia Friedle
- Daniel Jameson |
What
Adds lifetime tests (numpy
importorskip) for the numpy peak-data getters:MSSpectrum.get_peaks()→(mz, intensity)MSExperiment.get2DPeakData()→(rt, mz, intensity)MSExperiment.get2DPeakDataLong()→(rt, mz, intensity)Each test snapshots the returned arrays while the source is still alive, then
dels it +gc.collect(), then asserts the arrays are byte-identical. Snapshot-before-delete keeps the assertion non-vacuous.Why
Closes the "numpy getters" part of the §2 (pyOpenMS nanobind rewrite)
[AUTO]zero-copy task in the OpenMS 3.6.0 pre-release testing plan (#9460):These getters return numpy arrays whose buffer is owned by an
nb::capsule(delete[]), independent of the C++ source — so they're safe today, but the issue flags the "risk is a future view-returning edit." This pins the contract: if a getter is ever changed to return a view into the source buffer, the test fails after the source is GC'd.test_spectrum_zerocopy.pyalready coversget_peaks_struct(), and #9543 (companion PR) covers the Arrow exporters; this covers theget_peaks()/get2DPeakData()getters the issue's coding-agent prompt names explicitly.Test plan
Tests only — no production code changed. Verified against the built nanobind bindings two ways: direct script (
All numpy-getter lifetime tests passed!) andpytest(3 passed).numpyimportorskipkeeps it optional; thespectrum/experiment/kernelmodules used are unaffected by the unrelated stale-build_pyopenms_analysiswarning.Part of #9460. Follows #9524 … #9543.
🤖 Generated with Claude Code
Summary by CodeRabbit