-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
np.average crashes for 1D decimal object array (now only without weights) #8696
Comments
Yes, this seems like a bug and certainly doesn't reflected the intended behavior as described in the docs. Decimal arrays should be acceptable as arguments for this function. |
Apparently the problem had regressed - I've just seen it with numpy 1.16.2 (Python 3.7 on Windows). |
The test is still there, and presumably passing in CI: numpy/numpy/lib/tests/test_function_base.py Lines 376 to 380 in dea1239
Either your installation is a mixture of different versions, or you're seeing a different problem |
I presume the test is for the case when weights are provided; my problem appears for average without weights:
A mixture of different versions is quite improbable - this is a new computer for a new project, where I've just installed Python and numpy... |
Turns out we didn't read the issue carefully enough:
We only fixed one of these two problems. Fixing this is another case where #13105 would help us... |
Any updates on this? I've found similar issue, but without the x_model = np.average(x, weights=weights) # where x and weights are a np.array of floats Output error is (run at
Upgrade numpy to 1.16 solves the issue for me. |
The issue seems to be still relevant when |
I'm running macOS 10.12.3, Python 3.6.0, and NumPy 1.12.0.
When using the decimal package with NumPy, the arrays are of type 'object'. While most operations are performed flawlessly, calling np.average() with one of these arrays throws an error if weights are not provided (
AttributeError: 'decimal.Decimal' object has no attribute 'dtype'
), and a different error if weights are provided (AttributeError: 'bool' object has no attribute 'any'
). Contrarily, calling np.mean() executes without error.The source of the problem in both cases appears to be the assumption that the result of folding the input array results in a standard supported dtype, rather than being based on the operations available to the object type.
Therefore, I suspect that this issue will extend to any types which support the requisite numeric operations but are not natively supported by NumPy.
I resolved the weighted problem for my use case by changing the line
if (scl == 0.0).any()
(line 1138 inlib/function_base.py
) to check if scl were an array first, and if not then removing theany()
call, though I don't know if that solution is desirable or acceptable for the purposes of NumPy.Sample input:
Corresponding output:
The text was updated successfully, but these errors were encountered: