Skip to content

Commit 9f412d4

Browse files
committed
Add test of setting from a masked column astropy#2997
1 parent 84089db commit 9f412d4

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎astropy/table/tests/test_masked.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,25 @@ def test_add_masked_row_to_non_masked_table_iterable(self):
375375
assert np.all(t['a'].mask == np.array([0, 0, 0], bool))
376376
assert np.all(np.array(t['b']) == np.array([4, 5, 6]))
377377
assert np.all(t['b'].mask == np.array([0, 0, 1], bool))
378+
379+
380+
def test_setting_from_masked_column():
381+
"""Test issue in #2997"""
382+
mask_b = np.array([True, True, False, False])
383+
for select in (mask_b, slice(0, 2)):
384+
t = Table(masked=True)
385+
t['a'] = Column([1, 2, 3, 4])
386+
t['b'] = MaskedColumn([11, 22, 33, 44], mask=mask_b)
387+
t['c'] = MaskedColumn([111, 222, 333, 444], mask=[True, False, True, False])
388+
389+
t['b'][select] = t['c'][select]
390+
assert t['b'][1] == t[1]['b']
391+
assert t['b'][0] is np.ma.masked # Original state since t['c'][0] is masked
392+
assert t['b'][1] == 222 # New from t['c'] since t['c'][1] is unmasked
393+
assert t['b'][1] == 33
394+
assert t['b'][1] == 44
395+
assert np.all(t['b'].mask == t.mask['b']) # Avoid t.mask in general, this is for testing
396+
397+
mask_before_add = t.mask.copy()
398+
t['d'] = np.arange(len(t))
399+
assert np.all(t.mask['b'] == mask_before_add['b'])

0 commit comments

Comments
 (0)