Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX avoid warning in input validation with array_api_strict #29086

Conversation

ogrisel
Copy link
Member

@ogrisel ogrisel commented May 23, 2024

Here is a reproducer for the original problem fixed in this PR.

In [11]: import numpy as np

In [12]: X = xp.asarray(np.random.randn(10000, 10))

In [13]: from sklearn.decomposition import PCA

In [14]: import sklearn

In [15]: sklearn.set_config(array_api_dispatch=True)

In [16]: PCA().fit(X).explained_variance_ratio_
/Users/ogrisel/code/scikit-learn/sklearn/utils/validation.py:106: UserWarning: You are comparing a array_api_strict dtype against a NumPy native dtype object, but you probably don't want to do this. array_api_strict dtype objects compare unequal to their NumPy equivalents. Such cross-library comparison is not supported by the standard.
  if X.dtype == np.dtype("object") and not allow_nan:

I don't think it's worth adding a non-regression test just for an annoying warning.

Copy link

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 253e360. Link to the linter CI: here

Copy link
Member

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

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

LGTM. Okay to not add a test for that

@thomasjpfan thomasjpfan added this to the 1.5.1 milestone May 23, 2024
@thomasjpfan thomasjpfan added the To backport PR merged in master that need a backport to a release branch defined based on the milestone. label May 23, 2024
@thomasjpfan thomasjpfan merged commit 60e4acd into scikit-learn:main May 23, 2024
36 checks passed
@ogrisel ogrisel deleted the fix-warning-array_api_strict-in-input-validation branch May 24, 2024 12:42
jeremiedbb pushed a commit to jeremiedbb/scikit-learn that referenced this pull request Jul 2, 2024
@jeremiedbb jeremiedbb mentioned this pull request Jul 2, 2024
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Array API module:utils No Changelog Needed To backport PR merged in master that need a backport to a release branch defined based on the milestone.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants