Skip to content
Snippets Groups Projects
Commit dda966a3 authored by Martin Lange's avatar Martin Lange
Browse files

fix unquantified masked arrays loosing mask in fm.data.prepare()

parent 4415a536
No related branches found
No related tags found
1 merge request!270Fix unquantified masked arrays loosing mask in fm.data.prepare()
Pipeline #194068 failed with stages
in 4 minutes and 14 seconds
......@@ -77,7 +77,7 @@ def prepare(data, info, time_entries=1, force_copy=False, report_conversion=Fals
# this covers masked arrays as well
if isinstance(data, np.ndarray):
if force_copy:
data = np.copy(data)
data = data.copy()
data = UNITS.Quantity(data, units)
else:
if force_copy:
......
......@@ -207,6 +207,29 @@ class TestDataTools(unittest.TestCase):
xdata2[0, 0] = 0 * finam.UNITS("m")
self.assertNotEqual(0.0, data[0])
def test_prepare_masked(self):
time = dt(2000, 1, 1)
info = finam.Info(
time,
grid=finam.UniformGrid((3, 4), data_location=finam.Location.POINTS),
units="",
)
in_data = np.ma.MaskedArray(np.ndarray((3, 4)), mask=False)
in_data.mask[0, 0] = True
xdata = finam.data.prepare(in_data, info, force_copy=True)
self.assertTrue(finam.data.is_masked_array(xdata))
self.assertTrue(xdata.mask[0, 0, 0])
self.assertFalse(xdata.mask[0, 1, 0])
in_data = finam.data.quantify(in_data)
xdata = finam.data.prepare(in_data, info, force_copy=True)
self.assertTrue(finam.data.is_masked_array(xdata))
self.assertTrue(xdata.mask[0, 0, 0])
self.assertFalse(xdata.mask[0, 1, 0])
def test_assert_type(self):
finam.data.assert_type(self, "A", 1, [int, float])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment