From dda966a3d4a3e1c6e9c6f250835ddf234689b9d6 Mon Sep 17 00:00:00 2001 From: Martin Lange Date: Fri, 20 Oct 2023 20:39:11 +0200 Subject: [PATCH 1/2] fix unquantified masked arrays loosing mask in fm.data.prepare() --- src/finam/data/tools.py | 2 +- tests/data/test_tools.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/finam/data/tools.py b/src/finam/data/tools.py index 78c07d4..00743de 100644 --- a/src/finam/data/tools.py +++ b/src/finam/data/tools.py @@ -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: diff --git a/tests/data/test_tools.py b/tests/data/test_tools.py index eb35087..4f1c1b4 100644 --- a/tests/data/test_tools.py +++ b/tests/data/test_tools.py @@ -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]) From 3816491d975f91c4d954e0d59ffeef9ec4fd86e5 Mon Sep 17 00:00:00 2001 From: Martin Lange Date: Fri, 20 Oct 2023 20:49:23 +0200 Subject: [PATCH 2/2] update changelog, upgrade pylint due to AsteroidError --- .gitlab-ci.yml | 2 +- CHANGELOG.md | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4e9caa6..6c3cd9b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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 . diff --git a/CHANGELOG.md b/CHANGELOG.md index 423c90b..5fc72a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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