data-apis / array-api-tests

Test suite for the PyData Array APIs standard
https://data-apis.org/array-api-tests/
MIT License
63 stars 39 forks source link

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

Closed fnhirwa closed 5 months ago

fnhirwa commented 5 months ago

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 commented 5 months ago

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

fnhirwa commented 5 months ago

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 commented 5 months ago

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

honno commented 5 months ago

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 Hypothesis[^1]. Given support for latest NumPy/CuPy isn't that critical, I'd rather keep the maintenance overhead minimal too.

[^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.