Repository navigation
BUG: fix importing numpy in Python's optimized mode - #27868
Conversation
| @@ -21,6 +22,11 @@ | |||
|
|
|||
| def get_array_function_like_doc(public_api, docstring_template=None): | |||
There was a problem hiding this comment.
I realized that changing the default value for docstring_template to an empty string would probably work too, but I cannot test it right now (afk).
mhvk
left a comment
There was a problem hiding this comment.
This looks good but perhaps good to follow #27866 (comment) and also change a CI test to ensure this does not recur.
|
sure thing. What for would be appropriate ? Do we want to run the whole test suite or just try |
|
The whole test suite, and no new job needed I think - just adding |
9211175 to
c1166d5
Compare
|
Interesting, this found one failing test under PYTHONOPTIMIZE=2 . Let me try to fix this too. |
|
Only the test itself didn't support optimized mode because it relied on having IO operations evaled through assert statements. Separating evaluation from assertion should do the trick (it works locally, at least). |
|
Does this mean that all the I wonder if we can pick a shorter run and just do tests twice, as in (Checking this locally on another project, I get a failure because astropy can also not be loaded with Alternatively, perhaps we do need a special branch that just imports everything? |
yes. That is a direct expectation from running python with |
|
Wasn't that fixed? IIRC that was a main reason for us avoiding plain |
|
Oh yes, sorry, I see from doing more experiments with it locally that actually, only though, I don't understand why that one test needed tweaking... |
mhvk
left a comment
There was a problem hiding this comment.
It was the test tweak that made me wonder - I also thought this was fixed. Just to be sure, I also confirmed that a failing test actually fails with optimization on.
Anyway, chalk it up to the mysteries of python...
|
For reference, |
|
My guess is that this is due to: i.e. the module is already imported before pytest does its magic. I think it would be nice if pytest would warn (or even error) but dunno if that is doable. Maybe open an issue there? So an alternative fix would be moving the But, since that seems the reason, this work-around is also not a big deal. EDIT: To be clear, the full file has no asserts in this test run. But, it is also only this test file that seems to be imported anywhere. |
rgommers
left a comment
There was a problem hiding this comment.
This seems to do the job, so while we're pondering the pytest magic related hiccups, I'll go ahead and merge this and rebuild the nightly wheels to avoid more issues downstream (the failing SciPy CI job needs a local fix though, since it currently pulls in numpy 2.2.0rc1).
|
Thanks @neutrinoceros, @mhvk and @seberg! |
* TST: add PYTHONOPTIMIZE=2 to full CI (linux) * BUG: fix importing numpy in Python's optimized mode * TST: fix a test for compatibility with PYTHONOPTIMIZE
BUG: fix importing numpy in Python's optimized mode (#27868)
Follow up to gh-27490, fix gh-27866