Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FIX PoissonRegressor mixed namespace/device array API inputs - #34480

Merged
virchan merged 1 commit into
scikit-learn:mainfrom
aminehd:poissonregressor-mixed-array-api-inputs
Jul 24, 2026
Merged

FIX PoissonRegressor mixed namespace/device array API inputs#34480
virchan merged 1 commit into
scikit-learn:mainfrom
aminehd:poissonregressor-mixed-array-api-inputs

Conversation

@aminehd

@aminehd aminehd commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Towards #28668

What does this implement/fix?

PoissonRegressor (via _GeneralizedLinearRegressor) already called move_to
on y and sample_weight in fit and score, but only after the
dtype-coupled validation (check_array / _check_sample_weight), which uses
X's dtype. When y/sample_weight came from a different array API
namespace/device than X, this raised before the move
(array_api_strict.isdtype receiving a torch.dtype).

This moves y and sample_weight onto X's namespace/device before that
validation in both methods, and removes the check_array_api_mixed_inputs
XFAIL for PoissonRegressor. move_to is a no-op in the same-namespace path.

Testing

SCIPY_ARRAY_API=1 pytest -k "array_api_mixed_inputs and PoissonRegressor",
on CPU and on GPU (NVIDIA RTX 4060 Ti, torch 2.13.0+cu126):

  • before: 2 failed (TypeError: 'dtype' must be a dtype, not torch.dtype)
  • after: 2 passed (incl. CPU-numpy y → GPU-torch X); 3 skipped (cupy / mps
    backends absent)

No regressions: test_glm.py 406 passed; the one pre-existing PoissonRegressor
failure (check_array_api_input[array_api_strict, device1, float32]) also fails
on unmodified main.

AI usage disclosure

I used AI assistance (Claude) for:

  • Research and understanding — tracing the failure through check_array /
    _check_sample_weight to the misplaced move_to.
  • Code generation — the move_to reorder in fit and score.
  • Testing — the CPU/GPU verification runs and before/after checks.
  • Documentation — the changelog fragment.

I reviewed and verified all of it myself and take responsibility for its correctness.

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

@aminehd
aminehd force-pushed the poissonregressor-mixed-array-api-inputs branch from 12df4ae to dd3b48c Compare July 15, 2026 03:19

@OmarManzoor OmarManzoor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for the PR @aminehd. There are some conflicts that might need to be resolved.

Comment thread doc/whats_new/upcoming_changes/array-api/34480.fix.rst
Comment thread sklearn/linear_model/_glm/glm.py Outdated
@aminehd
aminehd force-pushed the poissonregressor-mixed-array-api-inputs branch from 51c1bcb to f0dc92c Compare July 22, 2026 17:24
@aminehd

aminehd commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Hi @OmarManzoor , Thanks for the review, applied all comments and resolved merge conflict.
Updated the branch in the pr.

@OmarManzoor OmarManzoor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Thank you @aminehd

Comment thread doc/whats_new/upcoming_changes/array-api/34480.fix.rst
@OmarManzoor OmarManzoor added the Waiting for Second Reviewer First reviewer is done, need a second one! label Jul 22, 2026
@OmarManzoor

Copy link
Copy Markdown
Contributor

CC: @lucyleeow @virchan for a second review

@aminehd
aminehd force-pushed the poissonregressor-mixed-array-api-inputs branch from 71c9b88 to d1480ce Compare July 22, 2026 18:23
`_GeneralizedLinearRegressor.fit` and `score` moved `y` and `sample_weight`
onto `X`'s namespace/device only after the dtype-coupled validation
(`check_array` / `_check_sample_weight`), which uses `X`'s dtype. With `y` or
`sample_weight` in a different array API namespace/device than `X` this raised
(e.g. `array_api_strict.isdtype` receiving a `torch.dtype`).

Move `y` and `sample_weight` before that validation in both methods, and drop
the `check_array_api_mixed_inputs` XFAIL for `PoissonRegressor`. `move_to` is a
no-op in the same-namespace path.

Towards scikit-learn#28668
@aminehd
aminehd force-pushed the poissonregressor-mixed-array-api-inputs branch from d1480ce to c45845a Compare July 22, 2026 18:25
@aminehd

aminehd commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @OmarManzoor . I changed the document file name.

@virchan virchan 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, @aminehd!

@virchan
virchan merged commit 372c786 into scikit-learn:main Jul 24, 2026
38 checks passed
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
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.

3 participants