You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Structured MaskedColumn do not display the mask correctly #16387
As noted by @taldcroft in #16380, a structured MaskedColumn does not look quite right (see example below). It likely means adjusting the default format for columns.
Expected behavior
The mask on individual parts of the structure should be shown, with unmasked elements properly displayed.
I'm not sure the issue is a with the column repr alone; digging a little bit in that direction I find that there's already a problem with how column elements are represented, and it seems that the problem with columns is merely a symptom of it
The following patch in numpy seems to resolve the problem
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 89b4f0703..7f1039267 100644
--- a/numpy/ma/core.py+++ b/numpy/ma/core.py@@ -3299,7 +3299,7 @@ def _scalar_heuristic(arr, elem):
# Did we extract a single item?
if scalar_expected:
# A record
- if isinstance(dout, np.void):+ if isinstance(dout, (np.void, mvoid)):
# We should always re-cast to mvoid, otherwise users can
# change masks on rows that already have masked values, but not
# on rows that have no masked values, which is inconsistent.
however I'm a little hesitant to upstream this without a deeper understanding. In particular, I don't know how to illustrate the issue without using astropy, I cannot yet write a pure-numpy test for it.
Unfortunalely this is not a reproducer for this issue (and is not solved by my patch), because it uses np.ma.moid.__getitem__, whereas the reproducer we have for astropy uses np.ma.MaskedArray.__getitem__, but it seems connected.
I'm still looking for a way to re-create the original problem without astropy.
Activity
neutrinoceros commentedon May 5, 2024
I'm not sure the issue is a with the column repr alone; digging a little bit in that direction I find that there's already a problem with how column elements are represented, and it seems that the problem with columns is merely a symptom of it
I'll take the rest of the day off, but I'm game to take a closer look tomorrow.
neutrinoceros commentedon May 6, 2024
It might actually go even deeper. Internally,
MaskedColumn.__getitem__retrieves the element assee
astropy/astropy/table/_column_mixins.pyx
Line 86 in 04fe653
I'm starting to suspect this might be a numpy bug.
neutrinoceros commentedon May 6, 2024
but then again, maybe not:
neutrinoceros commentedon May 6, 2024
The following patch in numpy seems to resolve the problem
however I'm a little hesitant to upstream this without a deeper understanding. In particular, I don't know how to illustrate the issue without using astropy, I cannot yet write a pure-numpy test for it.
neutrinoceros commentedon May 7, 2024
@mhvk @taldcroft what do you think ? Should I look for a pure numpy reproducer and report upstream or do you still think it's a problem on our side ?
neutrinoceros commentedon May 8, 2024
It looks like
np.ma.mvoidis pretty inconsistent with how masked/unmasked data is displayedUnfortunalely this is not a reproducer for this issue (and is not solved by my patch), because it uses
np.ma.moid.__getitem__, whereas the reproducer we have for astropy usesnp.ma.MaskedArray.__getitem__, but it seems connected.I'm still looking for a way to re-create the original problem without astropy.
taldcroft commentedon May 8, 2024
@neutrinoceros - what numpy version is this? is anything magically better in numpy 2.0?
neutrinoceros commentedon May 8, 2024
It's not, I tried numpy 1.26 and 2.0.0rc1 and they behave exactly the same here.