Skip to content

Commit

Permalink
Fix bug setting items in bytes MaskedColumn
Browse files Browse the repository at this point in the history
  • Loading branch information
taldcroft committed Dec 2, 2023
1 parent 9ce2087 commit a1d7486
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion astropy/table/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ def _encode_str(value):
elif isinstance(value, bytes) or value is np.ma.masked:
pass
else:
arr = np.asarray(value)
arr = np.asanyarray(value)
if arr.dtype.char == "U":
arr = np.char.encode(arr, encoding="utf-8")
if isinstance(value, np.ma.MaskedArray):
Expand Down
7 changes: 7 additions & 0 deletions astropy/table/tests/test_masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,3 +651,10 @@ def __new__(cls, *args, **kwargs):
# repr should need none (used to be 2!!)
repr(c0)
assert MyBaseColumn.counter == 2


def test_set_masked_bytes_column():
mask = [True, False, True]
mc = MaskedColumn([b"a", b"b", b"c"], mask=mask)
mc[:] = mc
assert (mc.mask == mask).all()
4 changes: 4 additions & 0 deletions docs/changes/table/15669.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Fix a Table bug when setting items (via slice or index list) in a ``bytes`` type
``MaskedColumn`` would cause the column mask to be set to all ``False``. A common way to
trigger this bug was reading a FITS file with masked string data and then sorting the
table.

0 comments on commit a1d7486

Please sign in to comment.