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
BUG: fix sparse random int handling #9486
Conversation
Adding the test failure for clarity:
|
I can't say I get the logic of either the original code or the fix, it's unclear to me what the options are for Note that if this takes a while to resolve, you could also consider reverting that PR in 1.2.x. The problem seems to be for numpy <1.11.0 only, which we're dropping in master very soon. |
--- a/scipy/_lib/_numpy_compat.py
+++ b/scipy/_lib/_numpy_compat.py
@@ -95,6 +95,11 @@ else:
# method of RandomState does only work with int32 values.
def get_randint(random_state):
def randint_patched(*args, **kwargs):
+ # args should be: low, high, size
+ # kwargs should only really contain
+ # dtype argument not available in older
+ # NumPy versions, which couldn't handle
+ # int64
try:
low = args[0]
size = args[2] The patched function is probably a bit awkward though, and may be important to check which of its codepaths are actually tested locally. The top of |
This shim is only used in one place right now, in if np.issubdtype(dtype, np.integer):
randint = get_randint(random_state)
def data_rvs(n):
return randint(np.iinfo(dtype).min, np.iinfo(dtype).max,
n, dtype=dtype) Since the shim will be obsolete once the minimum numpy version is increased, I think it's sufficient to patch it here to get tests running, without worrying too much about having all the corner cases checked. In particular, we know that both |
028a06a
to
6a9b110
Compare
Revised based on revisions requested from CJ, though I don't have immediate access to the local test environment originally used for reproduction since I'm at BIDS at the moment. |
* TestConstructUtils::test_random_sampling fails in some SciPy wheel build scenarios because of incorrect handling of np.int32/64 limits in the compatibility layer; this commit attempts to fix that behavior
6a9b110
to
f9ad4bd
Compare
I reproduced the original test failure locally on the latest master branch (04c0e5f) using above-described dependencies & then confirmed that the test passes on the revised version of this PR branch (f9ad4bd) in the same environment. CI is all-green too. If there's still too much concern about the shim after the simplifications above then I should probably consider the PR reversion. |
LGTM now, merged. Thanks @tylerjereddy and @perimosocordiae |
Unfortunately we're still getting a related wheel build failure with It looks like we really do have to ensure that all arguments to |
Out of all distributions available, it's only |
* backports for scipygh-9486, scipygh-9494, scipygh-9512, scipygh-9507, scipygh-9526
#9550 might fix the problem with |
SciPy wheel builds have been failing for the last ten weeks, which has caused a number of issues to fly under the radar until my attempt to start the wheel build process for
1.2.0rc1
as described in MacPython/scipy-wheels#37.This PR targets perhaps the most worrisome of the failures, in
scipy.sparse.tests.test_construct::TestConstructUtils::test_random_sampling
.I was able to reproduce one of the several failing wheel build matrix entries locally by using
numpy==1.8.2
,Cython==0.29.0
,Python==2.7
, and SciPy master branch.The changes made in this PR were sufficient to patch that specific test failure locally, but that doesn't mean we actually want to fix it this way, and I'm not sure how imposing this fix is after the branch has happened--maybe not too cumbersome yet without a tag having been pushed.
The original compatibility layer addition was quite recent -- #9048 by @jor-.