-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
PEP 3141 numbers should be considered scalars #9691
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
Conversation
I'd argue that |
@eric-wieser - since it is used in the wild, we still might want to ensure it works as advertised. Possibly, we can add @jdemeyer - I think the PR as stands is useful already - but could you add a test case? |
I guess my point is that I would consider it to be a bug in scipy that |
@eric-wieser - but where do we document this? Doesn't it make more sense that Also, more practically, this PR would seem to be an improvement no matter what... |
What do you mean with a test case? Isn't the |
...or do you mean that I should implement a new class based on |
Tests changed as requested. |
@jdemeyer - yes, I meant a test with p.s. Sadly, tests in the docs are actually not run in numpy... |
OK, that explains your earlier comment. |
@jdemeyer You should do your work in a branch rather than master. |
You are certainly right in principle, but for a one-off pull request like this, that doesn't matter. Are the tests OK now? |
Anything else preventing this to be merged? |
I have a feeling this might change the behaviour of I'd be happier if we could remove all internal uses of |
This seems reasonable to me. @mhvk I don't think this causes a problem with linspace. Is it the case that numbers with units are not considered Numbers? |
@charris - our |
My question here was whether |
My primary objection here is that if we're going to change behavior of def isscalar(x):
return np.ndim(x) == 0 or perhaps with less breakage, def isscalar(x):
# still refuses to consider 0d arrays scalars
return not isinstance(x, np.ndarray) and np.asarray(x).ndim == 0 There are other bugs (#9898) that this would fix at the same time |
Your simplest example would definitely break things for Maybe more relevantly, I don't think this has to hold up this particular PR: it just allows for classes that have specifically stated they are number-like by registering as such -- which I think is hard to argue against. Anyway, my suggestion would be (1) merge this PR; (2) open new issue that we should look carefully in our own code base what |
The answer is:
|
well, it sounds like step (2) would be relatively easy! (In the meantime, this PR still fixes a real bug... even if it is in scipy.) |
If @kiwifb can confirm that |
Haven't heard back from @kiwifb . I am going to put this in, we can fix it later if things go wrong. |
Thanks @jdemeyer . |
Sorry, was a bit busy. We have been using this patch (@jdemeyer wrote it for sage after all) for the last month or so and we haven't seen side effects. |
So |
I don't see a difference before and after. |
The function
numpy.isscalar()
should recognize all PEP 3141 numbers as scalars.The underlying issue is that the upgrade to SciPy 0.19.1 broke
lil_matrix()
with Sage Integers as input, because SciPy now usesnumpy.isscalar()
to validate certain inputs.Downstream: https://trac.sagemath.org/ticket/23867