Skip to content

Added check for numpy version as np.bool is deprecated #251

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

Closed
wants to merge 5 commits into from
Closed

Added check for numpy version as np.bool is deprecated #251

wants to merge 5 commits into from

Conversation

fnhirwa
Copy link

@fnhirwa fnhirwa commented Apr 8, 2024

Numpy deprecated the use of np.bool since version: 1.20.0
https://numpy.org/devdocs/release/1.20.0-notes.html#using-the-aliases-of-builtin-types-like-np-int-is-deprecated

With the current version of Numpy when I ran the tests I was getting the following errors

By setting numpy as array_module: os.environ["ARRAY_API_TESTS_MODULE"] = "numpy"
image

The reason for this is that some frameworks like ivy implement the array-api functions using numpy as core module, I understand that numpy added an extension for the Array-api interface via numpy.array_api (still experimental) but this might be worth supporting for such frameworks implementing Array API using numpy.

@rgommers
Copy link
Member

rgommers commented Apr 8, 2024

Note that in numpy 2.0.0 the main numpy namespace is array API standard compliant, including np.bool.

@fnhirwa
Copy link
Author

fnhirwa commented Apr 8, 2024

Note that in numpy 2.0.0 the main numpy namespace is array API standard compliant, including np.bool.

Ahhhhh!
I see it, should I change the logic in this PR to ensure that for numpy 2.0.0 and above xp.bool is as usual?
Or if this PR mix things up we can close it for now😊

@asmeurer
Copy link
Member

asmeurer commented Apr 8, 2024

This sort of fix is still useful. The test suite is currently unusable with the latest versions of numpy or cupy.

@honno
Copy link
Member

honno commented Apr 11, 2024

Thanks for the PR @fnhirwa! I agree with you and Aaron that it'd be nice for NumPy and CuPy to work out-of-the-box—this shouldn't be an issue for future versions but would be nice to test older versions still.

I like the approach here of having a separated boolean variable from xp.bool, but unfortunately there are still Hypothesis internals to contend with when you don't have xp.bool. So instead I opened #252 which patches the top-level xp module's bool, which is a somewhat less honest approach but feels more appropriate, lest we start monkey patching Hypothesis1. Given support for latest NumPy/CuPy isn't that critical, I'd rather keep the maintenance overhead minimal too.

Footnotes

  1. If we did want to go that route (that can of worms was opened with hh.arrays() and st.floats()), one thing I'd prob prefer is just having a dtype_helpers.bool object, rather than a function we call for each test module.

@honno honno closed this Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants