-
-
Notifications
You must be signed in to change notification settings - Fork 11k
BUG: error in printing masked arrays #7621
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
Please don't post screen shots. Copy and paste your session instead. Please try to reproduce your problem with a smaller array. |
import numpy as np
foo = np.array([ 30. , 61. , 31. , 37. , 6. , 2. , 132. ,
27. , 38. , 48.7 , 3. , 72. , 37.5 , 5.1 ,
48. , 20.2 , 26. , 1.8 , 15.3 , 30.4 , 4.5 ,
8. , 13. , 31. , 51. , 36. , 42. , 42. ,
34. , 21. , 1.11, 1.11, 1.11, 1.11, 1.11,
1.11, 1.11, 1.11, 1.11, 1.11, 1.11, 1.11,
1.11, 1.11, 1.11, 1.11, 1.11, 1.11, 1.11,
1.11, 38. , 9. , 42. , 27. , 17. , 39. ,
29. , 58. , 137. , 13. , 1.11, 1.11, 1.11,
1.11, 1.11, 1.11, 1.11, 1.11, 1.11, 1.11,
1.11, 1.11, 1.11, 1.11, 1.11, 1.11, 1.11,
1.11, 1.11, 1.11, 1.11, 1.11, 1.11, 1.11,
1.11, 1.11, 1.11, 1.11, 1.11, 1.11, 1.11,
1.11, 1.11, 1.11, 1.11, 1.11, 1.11, 1.11,
1.11, 1.11, 1.11, 1.11, 1.11, 1.11, 1.11,
1.11, 1.11, 1.11, 1.11, 1.11, 1.11, 1.11,
1.11, 1.11, 1.11, 1.11, 1.11, 1.11, 1.11,
1.11, 1.11, 1.11, 1.11, 1.11, 1.11, 1.11,
1.11, 1.11])
np.ma.masked_equal(foo, value=1.11) yields:
|
Hmm, I get
|
I noticed that the mask shows up correctly in your output. |
This may be a
|
I've upgraded to numpy 1.11.0 and I now see your problem:
|
Same issue with
|
Here are some really odd displays:
|
Here is a clearer case demonstrating the problem:
|
I'm going to guess this came in with #6748. |
I don't have time to check but #6094 also comes to mind as well. |
The problem is related to Here is a simple demonstration:
The default value for |
@saimn - it looks like you've done some work in this area recently. |
@abalkin - Yes indeed. I did this while working / checking on 2D/3D arrays I guess, and it seems that the rule for the number on values printed on screen for 1D arrays is different ... I don't know exactly what is the rule / limit, and when filling |
@saimn - I cannot understand your logic in 593345a. It looks like you drop the middle values from the array leaving no indication for the subsequent code as to where to place the dots. Also, you only apply the new logic when mask is not nomask leading to spurious display differences between arrays with |
The logic for 1-D arrays is odd. A length 1001 array is contracted:
but a length 1000 one is printed in full. (I will not paste a screenful here.) |
@abalkin - The logic is just to reduce the size of the array, but still have enough values to use the same printing logic as before. So if there are enough values, the output should be the same (with the conversion to the object dtype, filling with |
Got it, but the constant |
Hmm with edit:
But then printing a shows the full data. |
Truncation logic may also be dtype specific. |
Is there a fix for this appropriate for 1.11.1? |
It seems that Numpy starts to truncate the array when it has more than 1000 elements, so for the 1D case, setting |
@saimn That sounds good as a quick fix. Long term, I think we should figure out a better way of printing masked arrays. |
Ref numpy#7621. numpy#6748 added `np.ma.MaskedArray._print_width` which is used to cut a masked array before printing it (to save memory and cpu time during the conversion to the object dtype). But this doesn't work correctly for 1D arrays, for which up to 1000 values can be printed before cutting the array. So this commit adds a new class variable `_print_width_1d` to handle the 1D case separately.
Ref numpy#7621. numpy#6748 added `np.ma.MaskedArray._print_width` which is used to cut a masked array before printing it (to save memory and cpu time during the conversion to the object dtype). But this doesn't work correctly for 1D arrays, for which up to 1000 values can be printed before cutting the array. So this commit adds a new class variable `_print_width_1d` to handle the 1D case separately.
Should be fixed by #7658. Closing, but woud be good if folks would give the fix a shot and see if they can cause trouble. |
This fixed the issue for me, thanks. |
Uh oh!
There was an error while loading. Please reload this page.
Numpy masked arrays do not fill correctly when constructed. In the example below, the values filled do not correspond to the mask (notice the big chunk of values in the middle that get filled when they should not:
The same happens with other masked array constructors, such as
masked_equal
. Strangely, if I usenan
as the mask value, it works as expected.Running NumPy 1.11.0 on Python 3.5.1 (OS X 10.11.4)
The text was updated successfully, but these errors were encountered: