Skip to content

Commit 952407c

Browse files
authored
Merge pull request #20836 from jdavies-st/votable-invalid-mask-column-shift
Keep columns aligned when invalid="mask" masks a VOTable TABLEDATA value
2 parents 7732926 + cd25513 commit 952407c

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

‎astropy/io/votable/tests/test_tree.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,3 +792,25 @@ def test_read_table_with_nrows(tabledata_format, nrows):
792792

793793
assert np.array_equal(column.mask, values.mask)
794794
assert np.array_equal(column.filled(-1), values.filled(-1))
795+
796+
797+
def test_read_bad_value_with_invalid_mask():
798+
"""
799+
Test that parse_single_table with invalid="mask" on a TABLEDATA row whose
800+
middle cell is not an integer masks that cell and keeps the cells after it
801+
in their own columns.
802+
"""
803+
content = b"""<?xml version="1.0"?>
804+
<VOTABLE version="1.4" xmlns="http://www.ivoa.net/xml/VOTable/v1.3">
805+
<RESOURCE><TABLE>
806+
<FIELD name="a" datatype="int"/>
807+
<FIELD name="b" datatype="int"/>
808+
<FIELD name="c" datatype="int"/>
809+
<DATA><TABLEDATA>
810+
<TR><TD>1</TD><TD>bad</TD><TD>3</TD></TR>
811+
<TR><TD>4</TD><TD>5</TD><TD>6</TD></TR>
812+
</TABLEDATA></DATA></TABLE></RESOURCE></VOTABLE>
813+
"""
814+
array = parse_single_table(io.BytesIO(content), invalid="mask").array
815+
816+
assert array.tolist() == [(1, None, 3), (4, 5, 6)]

‎astropy/io/votable/tree.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3125,7 +3125,7 @@ def _parse_tabledata(self, iterator, colnumbers, config):
31253125
else:
31263126
row[j] = value
31273127
row_mask[j] = mask_value
3128-
j += 1
3128+
j += 1
31293129
elif tag == "TR":
31303130
break
31313131
else:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Reading a TABLEDATA table with ``invalid="mask"`` put values in the wrong
2+
columns since astropy 7.0: when a value could not be converted, each value
3+
after it in the row moved one column to the left. That value is now masked
4+
and the rest of the row stays in place.

0 commit comments

Comments
 (0)