Skip to content

TST Make array API metric references explicit - #34317

Merged
ogrisel merged 5 commits into
scikit-learn:mainfrom
wgu9:fix-array-api-reference-dispatch
Jun 23, 2026
Merged

ogrisel merged 5 commits into
scikit-learn:mainfrom
wgu9:fix-array-api-reference-dispatch

Conversation

@wgu9

@wgu9 wgu9 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Fixes #34311.

What does this implement/fix? Explain your changes.

This makes the NumPy reference computations in metrics array API tests explicitly run with array_api_dispatch=False before comparing them against array_api_dispatch=True results. It also keeps the Y branch in test_pairwise_parallel_array_api from being skipped accidentally by using local loop variables.

I used AI assistance to help inspect the relevant test paths and draft this PR, then reviewed and tested the changes locally.

Any other comments?

Local checks:

  • git diff --check
  • python -m compileall sklearn/metrics/tests/test_common.py sklearn/metrics/tests/test_pairwise.py
  • SCIPY_ARRAY_API=1 python -m pytest sklearn/metrics/tests/test_pairwise.py -k "array_api" -q
  • SCIPY_ARRAY_API=1 python -m pytest sklearn/metrics/tests/test_common.py -k "test_array_api_compliance and pairwise_distances" -q

@github-actions

Copy link
Copy Markdown

Thank you for opening your first pull request to scikit-learn! 🎉

To help get your contribution reviewed, please make sure that:

  • You have filled out the pull request template.
  • The pull request addresses an existing issue that is ready for
    contribution (e.g. not tagged as "Needs Triage", "Needs Decision", ...).
    If you are proposing a new feature, please open an issue to discuss it first.
  • There are no other open pull requests already targeting the same issue.
  • You have followed the pull request checklist.
    In particular, linting and tests should pass.

@ogrisel ogrisel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR. LGTM.

Comment thread sklearn/metrics/tests/test_pairwise.py Resolved
Comment thread sklearn/metrics/tests/test_pairwise.py Resolved
Comment thread sklearn/metrics/tests/test_pairwise.py Outdated

n_job2_np = func(X_np, metric=metric, n_jobs=2, **kwds)
with config_context(array_api_dispatch=False):
n_job2_np = func(X_np, Y_np_val, metric=metric, n_jobs=2, **kwds)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The original invocation only passes X_np

Suggested change
n_job2_np = func(X_np, Y_np_val, metric=metric, n_jobs=2, **kwds)
n_job2_np = func(X_np, metric=metric, n_jobs=2, **kwds)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. I restored the original one-argument NumPy call for the Y=None case, while still passing Y_np for the explicit non-None Y branch.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@lucyleeow happy with this change?

@github-actions github-actions Bot added the CI:Linter failure The linter CI is failing on this PR label Jun 23, 2026
@github-actions github-actions Bot removed the CI:Linter failure The linter CI is failing on this PR label Jun 23, 2026
@github-actions github-actions Bot removed the CUDA CI label Jun 23, 2026
@ogrisel
ogrisel merged commit d2b5212 into scikit-learn:main Jun 23, 2026
43 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Array API Jun 23, 2026
@wgu9
wgu9 deleted the fix-array-api-reference-dispatch branch June 23, 2026 16:18
prady0t pushed a commit to prady0t/scikit-learn that referenced this pull request Sep 2, 2026
@jeremiedbb jeremiedbb mentioned this pull request Sep 8, 2026
14 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Explicitly set array_api_dispatch=False when computing reference values in array API tests

4 participants