Skip to content

BUG: r2_score was raising unnecessarily for pyarrow chunkedarray input - #33996

Merged
jeremiedbb merged 3 commits into
scikit-learn:mainfrom
MarcoGorelli:fix-r2-score-pa-ca
May 12, 2026
Merged

jeremiedbb merged 3 commits into
scikit-learn:mainfrom
MarcoGorelli:fix-r2-score-pa-ca

Conversation

@MarcoGorelli

@MarcoGorelli MarcoGorelli commented May 12, 2026 •

Copy link
Copy Markdown
Contributor

closes #33993

I haven't added a whatsnew note, because this addresses a regression introduced in #31127, which has not yet made its way into a release

Reference Issues/PRs

What does this implement/fix? Explain your changes.

AI usage disclosure

I used AI assistance for:

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Any other comments?

@lorentzenchr lorentzenchr 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.

The fix is correct. The test should be improved imo.
@MarcoGorelli thanks a lot


if nw.dependencies.is_into_dataframe(x) or nw.dependencies.is_into_series(x):
return nw.from_native(x).shape[0]
return nw.from_native(x, allow_series=True).shape[0]

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.

That’s for sure the right fix.

Comment thread sklearn/utils/tests/test_validation.py Resolved
@MarcoGorelli
MarcoGorelli marked this pull request as ready for review May 12, 2026 10:05

@lorentzenchr lorentzenchr 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.

Sorry, this review comment should have been included in my 1. reciew.

Comment thread sklearn/utils/tests/test_validation.py Outdated
assert_allclose(result, [False, True, True, False])


def test_r2_score_pa_chunked_array():

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.

We don‘t need r2_score. We can test _num_samples with a chunked array directly.

@lorentzenchr lorentzenchr added the Quick Review For PRs that are quick to review label May 12, 2026
@lorentzenchr lorentzenchr added this to the 1.9 milestone May 12, 2026

@jeremiedbb jeremiedbb 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.

LGTM. Thanks

@jeremiedbb
jeremiedbb merged commit 43b609e into scikit-learn:main May 12, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

r2_score() no longer supports pyarrow.ChunkedArray inputs

3 participants