Skip to content

[TEST] RankData: cross-validate rankdata against scipy.stats.rankdata (#9460) - #9530

Merged
timosachsenberg merged 1 commit into
OpenMS:developfrom
timosachsenberg:test/9460-rankdata-scipy-crosscheck
Jun 16, 2026
Merged

timosachsenberg merged 1 commit into
OpenMS:developfrom
timosachsenberg:test/9460-rankdata-scipy-crosscheck

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds a section to RankData_test that pins RankData::rankdata against reference outputs generated with SciPy 1.17.1 (scipy.stats.rankdata(a, method=…, nan_policy=…)):

  • a larger ties vector across all five tie methods (average / min / max / dense / ordinal);
  • a ties + NaN vector across both NaN policies:
    • propagate — SciPy 1.17.1 returns all-NaN for every method (which RankData matches);
    • omit — rank only the non-NaN values, NaN positions stay NaN.

Why

Closes the §7 [AUTO] gap in the OpenMS 3.6.0 pre-release testing plan (#9460):

Add a scipy-generated vector with ties/NaN to RankData_test (currently tiny hand vectors). Pass: ranks match scipy.stats.rankdata for every tie method + NaN policy.

RankData documents itself as replicating scipy.stats.rankdata, but the existing tests only used tiny hand-computed vectors and never cross-checked against SciPy. This locks the SciPy-parity contract.

Adversarial check

The header comment notes parity with "SciPy 1.16.2 docs". Because nan_policy='propagate' semantics have historically varied across SciPy versions, I first generated the ground truth on the installed SciPy (1.17.1) and confirmed RankData reproduces it byte-for-byte across every method × policy (via a standalone compile of the header-only class) before writing any assertion — so the test asserts a real, verified match rather than an assumed one. On 1.17.1, propagate is all-NaN for every method, which agrees with RankData.

Test plan

Tests only — no production code changed. Verified locally: SciPy ground-truth generated, standalone match confirmed, -fsyntax-only clean, full build green, test runs PASSED.

Part of #9460. Follows #9524, #9525, #9526, #9528.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Significantly expanded test coverage for ranking functionality with cross-validation against industry standards
    • Added comprehensive validation for multiple ranking methods and edge case handling
    • Enhanced testing for special numeric values across different processing modes

…OpenMS#9460)

The existing sections use tiny hand-computed vectors. This adds a section
pinning a larger ties vector and a ties+NaN vector against reference outputs
generated with SciPy 1.17.1 -- scipy.stats.rankdata(a, method=, nan_policy=) --
for every tie method (average/min/max/dense/ordinal) and both NaN policies:
- propagate: SciPy 1.17.1 returns all-NaN for every method (matches RankData)
- omit: rank only the non-NaN values, NaN positions stay NaN

Confirmed RankData reproduces SciPy 1.17.1 byte-for-byte across all
method x policy combinations before adding the assertions.

Verified: builds clean and the test runs PASSED.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

@timosachsenberg The following names might be missing from the AUTHORS file:

  • Timo Sachsenberg

Please consider applying the following patch:

--- AUTHORS	2026-06-15 15:26:58.132415700 +0000
+++ AUTHORS.new	2026-06-15 15:27:03.372235099 +0000
@@ -23,8 +23,8 @@
  - Chirag Dave
  - Chris Bauer
  - Chris Bielow
- - Christie Mathews
  - Christian Ehrlich
+ - Christie Mathews
  - Clemens Groepl
  - Cornelia Friedle
  - Daniel Jameson

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4aa5dcdd-9499-4f43-a241-4d260294d905

📥 Commits

Reviewing files that changed from the base of the PR and between aacd941 and 426b59e.

📒 Files selected for processing (1)
  • src/tests/class_tests/openms/source/RankData_test.cpp

📝 Walkthrough

Walkthrough

Adds a NaN-aware vector comparison helper expect_equal_real_or_nan and a new test section to RankData_test.cpp that cross-validates RankData::rankdata outputs against SciPy 1.17.1 reference values for all five tie methods and both NaNPolicy modes (Propagate and Omit).

Changes

RankData SciPy Cross-Validation Tests

Layer / File(s) Summary
NaN-aware comparison helper
src/tests/class_tests/openms/source/RankData_test.cpp
Introduces expect_equal_real_or_nan, which compares two vectors element-wise: asserts NaN when the expected element is NaN, otherwise uses TEST_REAL_SIMILAR.
SciPy-referenced rankdata test section
src/tests/class_tests/openms/source/RankData_test.cpp
Adds a START_SECTION cross-validating RankData::rankdata against SciPy 1.17.1 for Average, Min, Max, Dense, and Ordinal on a ties-only vector, plus NaNPolicy::Propagate (all NaN) and NaNPolicy::Omit (mixed rank/NaN) cases using the new helper.

Poem

🐰 Hop, hop through ranks and ties,
NaN or number — nothing hides!
SciPy says so, tests agree,
Average, Min, Max — all three!
Dense and Ordinal pass the gate,
Omit or Propagate — ranked straight. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically identifies the main change: adding a test that cross-validates RankData's rankdata function against SciPy's reference implementation, which is directly supported by the changeset that adds a new test section with comprehensive SciPy 1.17.1 validation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 unit tests (beta)
  • Create PR with unit tests

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.

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