Skip to content

Fix _safe_indexing with non integer arrays on array API inputs#32840

Merged
ogrisel merged 2 commits intoscikit-learn:mainfrom
ogrisel:fix-array-api-indexing
Dec 5, 2025
Merged

Fix _safe_indexing with non integer arrays on array API inputs#32840
ogrisel merged 2 commits intoscikit-learn:mainfrom
ogrisel:fix-array-api-indexing

Conversation

@ogrisel
Copy link
Copy Markdown
Member

@ogrisel ogrisel commented Dec 4, 2025

This is a fix for #32837.

While investigating the issue above, I realized that we needed unittest for array API support for _safe_indexing.

I am not yet sure if this problem already existing in 1.7 or not. If it was I will add a changelog entry.

@OmarManzoor
Copy link
Copy Markdown
Contributor

I tried on google colab with scikit-learn 1.7.2 but the error did not occur using the original snippet in the issue.

@ogrisel
Copy link
Copy Markdown
Member Author

ogrisel commented Dec 4, 2025

Since this bug did not exist in a previous release, I don't think we need to document this fix in the changelog.

Copy link
Copy Markdown
Contributor

@OmarManzoor OmarManzoor left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you @ogrisel

Comment on lines +56 to +57
else:
return array[key, ...] if axis == 0 else array[:, key]
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.

Do we need this here considering that this is the default return statement anyways at the end?

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.

I ran the CI locally with the else block commented out, and it passed with CUDA. Even the code mentioned in #32837 compiled without any issues. So I think it's safe to remove it here.

Copy link
Copy Markdown
Member

@virchan virchan left a comment

Choose a reason for hiding this comment

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

Just one minor comment. Otherwise, LGTM! Thanks, @ogrisel!

Comment on lines +56 to +57
else:
return array[key, ...] if axis == 0 else array[:, key]
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.

I ran the CI locally with the else block commented out, and it passed with CUDA. Even the code mentioned in #32837 compiled without any issues. So I think it's safe to remove it here.

@ogrisel ogrisel added the CUDA CI label Dec 5, 2025
@github-actions github-actions bot removed the CUDA CI label Dec 5, 2025
@ogrisel ogrisel enabled auto-merge (squash) December 5, 2025 13:27
@ogrisel
Copy link
Copy Markdown
Member Author

ogrisel commented Dec 5, 2025

I will open a follow-up PR to try to add a higher level estimator common test to discover other similar bugs in the future but that might take more time to get in and don't want to delay this fix and the release of 1.8.

@ogrisel ogrisel merged commit f1ad9f9 into scikit-learn:main Dec 5, 2025
44 checks passed
@ogrisel ogrisel deleted the fix-array-api-indexing branch December 5, 2025 15:14
lesteve pushed a commit to lesteve/scikit-learn that referenced this pull request Dec 9, 2025
@lesteve lesteve mentioned this pull request Dec 9, 2025
14 tasks
lesteve pushed a commit to lesteve/scikit-learn that referenced this pull request Dec 9, 2025
tonybaloney pushed a commit to tonybaloney/swe-complex-scikit-learn that referenced this pull request Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants