-
Notifications
You must be signed in to change notification settings - Fork 590
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
Test for compatibility with Numpy prerelease (2.0 is coming this month) #3950
Comments
potential test case: from hypothesis import given
from hypothesis.extra.array_api import make_strategies_namespace
import numpy as np
try:
import numpy.array_api
xps = make_strategies_namespace(numpy.array_api)
except ImportError:
xps = make_strategies_namespace(np)
dtypes = xps.floating_dtypes()
shapes = xps.array_shapes()
arrays = xps.arrays(dtype=dtypes, shape=shapes)
@given(arrays)
def test_array_strategy(arr):
# or even just `pass`
assert hasattr(arr, "dtype") as pointed out by @seberg, the cause might be the changed casting rules in |
I believe the issue is that the types in the return value of
finfo = np.finfo(np.float32)
type(finfo.smallest_normal) # builtin float
finfo = np.finfo(np.float32)
type(finfo.smallest_normal) # float32 One way to resolve this would be to simply pass Edit: or maybe not? Let me check again. import numpy.array_api as xp
import numpy as np
finfo = xp.finfo(np.float32)
type(finfo.smallest_normal) # float and the same with |
I'm not sure that this was on purpose - it could be, but I don't remember. And while >>> isinstance(np.float64(1.5), float)
True
>>> isinstance(np.float32(1.5), float)
False There were a lot of PRs that touched on |
This is just indirect promotion changes, but looks fine to me. Finfo might have more precision than builtin float anyway. |
to be clear (my edits may have been confusing): However, both
Apparently builtin |
Ah thanks for the clarification, I was indeed thinking you showed that NumPy changed, and not the strict array API namespace. (I don't recall the discussion but it doesn't seem ideal to specify a |
(no changes to the array API namespaces either, they also always returned the same thing – but something different than
long double support probably is something that should be considered in the future, but for now I agree, casting to |
Same here. Okay, less concerned then:)
There is no way to do anything different aside from changing from a scalar to a 0-D array. Which would be a breaking change, that doesn't seem warranted. |
pydata/xarray#8844 (comment) points out that this test is failing on the upcoming Numpy 2.0, and it looks like we're incompatible.
Specifically,
hypothesis.extra.array_api.make_strategies_namespace()
eventually callsnext_up()
on an instance ofnumpy.float32
, and makes the failing asserting that this is an instance of builtinfloat
.The text was updated successfully, but these errors were encountered: