BOT: Fix #363: Add metric adapter functions for external scoring metrics#1101
Draft
nikosbosse wants to merge 1 commit intomainfrom
Draft
BOT: Fix #363: Add metric adapter functions for external scoring metrics#1101nikosbosse wants to merge 1 commit intomainfrom
nikosbosse wants to merge 1 commit intomainfrom
Conversation
Add metric_adapt_binary_numeric() and metric_adapt_swap_args() to wrap external scoring functions for use with score(). These handle the two most common incompatibilities: factor-to-numeric conversion for binary observed values, and reversed argument order (predicted, observed). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1101 +/- ##
==========================================
+ Coverage 97.83% 97.84% +0.01%
==========================================
Files 35 36 +1
Lines 1845 1854 +9
==========================================
+ Hits 1805 1814 +9
Misses 40 40 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
nikosbosse
commented
Feb 13, 2026
Collaborator
Author
nikosbosse
left a comment
There was a problem hiding this comment.
CLAUDE: Approve — Clean, minimal implementation of two adapter factory functions (metric_adapt_binary_numeric and metric_adapt_swap_args) that solve a real usability gap for external metric integration. Code follows existing package patterns (identical factor conversion to brier_score), closures have correct formals for run_safely() compatibility, and the 10-test suite covers unit, integration, composability, validation, and pass-through scenarios. No issues found.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
metric_adapt_binary_numeric()— wraps external metrics that expect numeric 0/1observedvalues, converting the factor input that scoringutils uses for binary forecastsmetric_adapt_swap_args()— wraps external metrics withfunction(predicted, observed)signature to match scoringutils'function(observed, predicted)convention(observed, predicted, ...)formals, compatible withscore(),run_safely(), andpurrr::partial()Fixes #363
Root cause
Users cannot directly use external scoring functions in
score()when those functions expect a different argument order or numeric (not factor) binary observed values.purrr::partial()can fix extra parameters but cannot reorder positional arguments or perform type conversion.What this does
Creates two small adapter/wrapper factory functions that return closures with the correct signature. The adapters:
metric_adapt_binary_numeric)metric_adapt_swap_args)...for additional parameterspurrr::partial()for further customizationTest coverage
10 test cases covering:
score()for binary, point, and sample forecasts...pass-through)purrr::partial()Test plan
🤖 Generated with Claude Code