Skip to content

Commit

Permalink
Merge branch 'fix-lost-mask' into 'main'
Browse files Browse the repository at this point in the history
Fix unquantified masked arrays loosing mask in fm.data.prepare()

Closes #115

See merge request FINAM/finam!270
  • Loading branch information
mlange-42 committed Oct 20, 2023
2 parents 4415a53 + 3816491 commit 659e6f2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ stages:
check:
stage: test
before_script:
- pip3 install 'black>=23,<24' 'pylint<3' 'isort[colors]<6'
- pip3 install 'black>=23,<24' 'pylint>=3' 'isort[colors]<6'
script:
- pip3 install --editable .
- black --check --diff --color .
Expand Down
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release notes

## [v0.5.1]

### Bug fixes

* Fix unquantified masked arrays loosing mask in `fm.data.prepare()` (#115, !270)

## [v0.5.0]

### Features
Expand Down Expand Up @@ -196,7 +202,8 @@
* initial release of FINAM


[unpublished]: https://git.ufz.de/FINAM/finam/-/compare/v0.5.0...main
[unpublished]: https://git.ufz.de/FINAM/finam/-/compare/v0.5.1...main
[v0.5.1]: https://git.ufz.de/FINAM/finam/-/compare/v0.5.0...v0.5.1
[v0.5.0]: https://git.ufz.de/FINAM/finam/-/compare/v0.4.0...v0.5.0
[v0.4.0]: https://git.ufz.de/FINAM/finam/-/compare/v0.4.0-rc.2...v0.4.0
[v0.4.0-rc.2]: https://git.ufz.de/FINAM/finam/-/compare/v0.4.0-rc.1...v0.4.0-rc.2
Expand Down
2 changes: 1 addition & 1 deletion src/finam/data/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 23 additions & 0 deletions tests/data/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,29 @@ def test_prepare_copy(self):
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])

Expand Down

0 comments on commit 659e6f2

Please sign in to comment.