-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: dtype changed from float64 to int64 in scipy discrete_rv #27054
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
Comments
Is it only possible to build numpy main with cython master right now? I was getting this error until I installed the Cython nightly build:
|
I need to take a look what is going on in SciPy but I think SciPy relied on |
@oscarbenjamin The issue you're experiencing appears to be due to a change in behavior in the recent NumPy nightly builds. The error message indicates that the i array, which is passed to your _pmf method, has an integer data type (int64), causing an error when a negative integer power operation is attempted.
Hope this helps |
The workaround is not a trivial as it might seem. In context the code here is generated by a codeprinter from a symbolic expression in SymPy: In [27]: from sympy import *
In [28]: i = Symbol('i')
In [29]: e = (S(2)/3)**3 * 3**(1 - i)
In [30]: e
Out[30]:
1 - i
8β
3
ββββββββ
27
In [31]: f = lambdify(i, e)
In [32]: f
Out[32]: <function _lambdifygenerated(i)>
In [34]: print(f.__doc__)
Created with lambdify. Signature:
func(i)
Expression:
8*3**(1 - i)/27
Source code:
def _lambdifygenerated(i):
return (8/27)*3**(1 - i)
Imported modules: The code printers would have to be modified to handle this somehow and there would need to be some UI for a caller of In any case the first question is really whether it should be expected that the array would have an integer type at all. For the |
Given that the _pmf method is expected to handle integer inputs, but the function generated by lambdify from SymPy uses floating-point arithmetic, there is a need to bridge the gap between the expectations of integer inputs and the resulting floating-point computations.
Transparent Type Conversion in _pmf:
While modifying the code printer in SymPy or providing a user interface in lambdify for type handling would be a more extensive change, the immediate issue can be mitigated by ensuring that the _pmf method correctly handles type conversion. This approach is less intrusive and maintains compatibility with existing code. |
@Siddharth-Latthe-07 I didn't want to say anything at first but your comments are clearly generated by an LLM with minimal editing and are not relevant to the discussion in this issue. It might be reasonable for ChatGPT to offer this kind of advice for a novice user who wants to fix some simple code but that is not the situation here. I don't need ChatGPT to tell me how to modify the repro code to avoid this issue: I wrote that code deliberately so that it would demonstrate the issue. There has been a change in NumPy which now means that SymPy's usage of a SciPy function does not work any more. A change is now needed in at least one of NumPy, SciPy or SymPy and considering what should be changed or not is the purpose of this and the related SciPy and SymPy issues. The first thing that I want to establish is if NumPy and SciPy are going to keep this changed behaviour. |
@Siddharth-Latthe-07 any more of these useless comments and we will need to report you. See similar comments here and here. Many of us follow the git firehose for this repo, and do not appreciate getting spammed. |
Feel free to close this issue, indeed SciPy just needs to adapt to the changed type promotion of |
Thanks, I'll close this then. |
Describe the issue:
The issue is seen with the NumPy nightly wheels since a few days ago. I don't know what exactly the cause is because it is something happening inside SciPy but somehow an array ended up being a different dtype when passed through to the
_pmf
method shown below which causes it to fail with:Reproduce the code example:
Error message:
Python and NumPy Versions:
This is seen with the NumPy nightly wheels since a few days ago.
With released NumPy 2.0.1 the code runs to completion with
Runtime Environment:
No response
Context for the issue:
This comes from a SciPy issue: scipy/scipy#21272 and a SymPy issue sympy/sympy#26862
The text was updated successfully, but these errors were encountered: