8000 Raise RuntimeError instead of a warning when using array API without setting SCIPY_ARRAY_API=1 by ogrisel · Pull Request #29814 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

Raise RuntimeError instead of a warning when using array API without setting SCIPY_ARRAY_API=1 #29814

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

Conversation

ogrisel
Copy link
Member
@ogrisel ogrisel commented Sep 9, 2024

Fixes the UX problem described in #29549 by raising an exception instead of a warning.

In particular the warning is invisible when running pytest and is leading to a non-explicit error. @adrinjalali faced it again recently triggering this PR.

The alternative would be to skip individual scikit-learn tests where we know that scipy array API support is actually needed but this would require extra care when reviewing array API PRs.

@ogrisel
Copy link
Member Author
ogrisel commented Sep 9, 2024

Note that if scipy/scipy#21529 is implemented in some future version of scipy, we can automatically enable scipy's support from scikit-learn when needed instead of raising an exception.

Copy link
github-actions bot commented Sep 9, 2024

✔️ Linting Passed

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

Generated for commit: 054f9d0. Link to the linter CI: here

@ogrisel
Copy link
Member Author
ogrisel commented Sep 9, 2024

/cc @betatim @lesteve @OmarManzoor

@ogrisel
Copy link
Member Author
ogrisel commented Sep 9, 2024

Forgot to update the test. I am on it.

Copy link
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. Thanks @ogrisel

I think it is better this way as it communicates the requirement clearly.

@OmarManzoor OmarManzoor merged commit 3bb916f into scikit-learn:main Sep 10, 2024
40 of 42 checks passed
@ogrisel ogrisel deleted the raise-runtimerror-when-scipy-array-api-not-enabled branch September 10, 2024 09:10
@ogrisel
Copy link
Member Author
ogrisel commented Sep 10, 2024

Note that this makes the pytest fail conditionally on installing array-api-compat (otherwise the tests are skipped).

An alternative would be to raise the exception (as we do in this merged PR) but also skip the array API tests if SCIPY_ARRAY_API is not enabled.

@adrinjalali
Copy link
Member

I don't mind the current failure. It forces us to enable the flag for scipy, and I just set it in my profile and never think about it again.

@StefanieSenger
Copy link
Contributor
StefanieSenger commented Sep 15, 2024

I think having to set this environmental variable adds another obstacle for new contributors.
Will this error raise for every test run or only when certain libraries will be installed?

To navigate this error message, people first need to know how to translate "set the SCIPY_ARRAY_API=1 environment variable" into actions, which might not be so easy for people without a computer science background. Personally, I have learned that this means putting the variable in front of the command only a few weeks ago. By reading the last comment in this discussion, I have now also learned that exposing an environmental variable in my shell's rc file is equivalent to putting it in front of every command and it then provides the variable for all the processes started within the shell. But I was lucky to know how to find this information.

Issues, that you can only navigate around if you know how to:

  1. Running SCIPY_ARRAY_API=1 pytest some/path instead of permanently setting it up for new processes started from the shell doesn't pass it to the IDE.

  2. Also after exposing environmental variable in shell's rc file: the IDE will only know about it when started from within the terminal (for instance code .).

If the IDE doesn't know about SCIPY_ARRAY_API=1 the debugger fails and tests cannot be collected (resulting in a Pytest Discovery Error in VSCode without further information than the error type).

These are a lot of possible issues that new contributors might run into. If they also run into them if they don't have array_api libraries installed, then I would hope there is another solution.

@adrinjalali
Copy link
Member

I think new contributors wouldn't see this since they wouldn't install array-api-strict and/or array-api-compat, which means they wouldn't see this error(?).

For us, we can fix the issue by having a .env file in our local copy of the repo with this content:

$ cat .env 
SCIPY_ARRAY_API=1

This would be picked up by vscode/other vscode based IDEs. I had the same issue and had to figure it out. So it might make sense to have this info somewhere.

@StefanieSenger
Copy link
Contributor
StefanieSenger commented Sep 15, 2024

And it seems you then also need to configure your path to .env as "python.envFile" in the settings.json of VSCode somehow, which I fail to do. (No matter, I usually start it from the terminal anyways.)

Mentioning this because it seems that's not an easy solution neither. And when you have a path like this in your VSCode settings and then switch to another project which also uses an .env file?

@adrinjalali
Copy link
Member 8000

@StefanieSenger if you name the file .env, then you won't need to set python.envFile, that's only needed for files named other than .env.

@StefanieSenger
Copy link
Contributor

@StefanieSenger if you name the file .env, then you won't need to set python.envFile, that's only needed for files named other than .env.

Hm, well ... I did name my file .env and had put it on the top layer, outside of the sklearn package. Not sure why it's not working.
Not so relevant for my personal use, but it seems there are things than can go wrong here.

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.

4 participants
0