Commit 7cc59f6b authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Fixed a bug causing float nodata values to be rejected in case of integer array data types.


Signed-off-by: Daniel Scheffler's avatarDaniel Scheffler <danschef@gfz-potsdam.de>
parent 7efe2480
Pipeline #22803 failed with stages
in 10 minutes and 6 seconds
......@@ -2,6 +2,12 @@
History
=======
0.12.1 (2021-05-08)
-------------------
* Fixed a bug causing float nodata values to be rejected in case of integer array data types.
0.12.0 (2021-05-08)
-------------------
......
......@@ -139,12 +139,18 @@ class GeoArray(object):
def _validate_nodataVal(self):
"""Check if a given nodata value is within the valid value range of the data type."""
if (np.issubdtype(self.dtype, np.integer) and
not np.can_cast(self._initParams['nodata'], self.dtype)) or \
(np.issubdtype(self.dtype, np.floating) and
not np.can_cast(float(self._initParams['nodata']), self.dtype)):
_nodata = self._initParams['nodata']
if np.issubdtype(self.dtype, np.integer):
dt_min, dt_max = np.iinfo(self.dtype).min, np.iinfo(self.dtype).max
elif np.issubdtype(self.dtype, np.floating):
dt_min, dt_max = np.finfo(self.dtype).min, np.finfo(self.dtype).max
else:
return
if not dt_min <= _nodata <= dt_max:
raise ValueError("The given no-data value (%s) is out range for data type %s."
% (self._initParams['nodata'], self.dtype))
% (self._initParams['nodata'], str(np.dtype(self.dtype))))
@property
def arr(self):
......
......@@ -20,5 +20,5 @@
# with this program. If not, see <http://www.gnu.org/licenses/>.
__version__ = '0.12.0'
__versionalias__ = '20210508.01'
__version__ = '0.12.1'
__versionalias__ = '20210508.02'
......@@ -146,6 +146,10 @@ class Test_GeoArray(TestCase):
with self.assertRaises(ValueError):
GeoArray(np.array([1, 2]).astype(np.uint8), nodata=256)
# test float nodata value together with integer array data type
with self.assertRaises(ValueError):
GeoArray(np.array([1, 2]).astype(np.uint8), nodata=0.)
@parameterized.expand(_get_gA_inMem_notInMem())
def test_calc_mask_nodata(self, _, gA):
def test_with_flag_all(_gA):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment