Commit b692590c authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Fix exception in case of int and float bandnames in the input.

parent 3773e3e9
Pipeline #37151 passed with stage
in 2 minutes and 10 seconds
......@@ -199,8 +199,11 @@ class GeoArray(object):
"Received %s." % type(list_bandnames))
if len(list_bandnames) != self.bands:
raise ValueError('Number of given bandnames does not match number of bands in array.')
if len(list(set([type(b) for b in list_bandnames]))) != 1 or not isinstance(list_bandnames[0], str):
raise ValueError("'bandnames must be a set of strings. Got other datatypes in there.'")
if len(list(set([type(b) for b in list_bandnames]))) != 1:
raise ValueError('Multiple data types of the band names are not supported.')
if not isinstance(list_bandnames[0], (str, int, float)):
raise ValueError(f'Band names must be a set of strings, integers, or floats. '
f'Got {type(list_bandnames[0])}')
bN_dict = OrderedDict((band, i) for i, band in enumerate(list_bandnames))
......@@ -1054,7 +1057,7 @@ class GeoArray(object):
band = ds_out.GetRasterBand(bidx + 1)
if 'band_names' in envi_metadict:
bandname = self.metadata.band_meta['band_names'][bidx].strip()
bandname = str(self.metadata.band_meta['band_names'][bidx]).strip()
band.SetDescription(bandname)
assert band.GetDescription() == bandname
......@@ -1113,7 +1116,8 @@ class GeoArray(object):
# meta2write = dict((k, repr(v)) for k, v in self.metadata.band_meta.items() if v is not np.nan)
if 'band_names' in bandmeta:
band.SetDescription(self.metadata.band_meta['band_names'][bidx].strip())
bandname = str(self.metadata.band_meta['band_names'][bidx]).strip()
band.SetDescription(bandname)
del bandmeta['band_names']
if 'nodata' in bandmeta:
......
......@@ -506,7 +506,9 @@ class Test_GeoArray(TestCase):
gdalinfo_orig = [i + '\n' for i in getoutput(f'gdalinfo -mdd ENVI {path_subset_bsq}').split('\n')]
diff = ''.join(list(unified_diff(gdalinfo_orig[3:], gdalinfo_out[3:])))
self.assertFalse(diff)
self.assertFalse(diff,
f'\n\nThe gdalinfo output of the saved dataset contains some unexpected differences: \n\n'
f'{diff}')
# compare header files
with open(p_out[:-4] + '.hdr', 'r') as inF:
......@@ -530,7 +532,9 @@ class Test_GeoArray(TestCase):
gdalinfo_orig = [i + '\n' for i in getoutput(f'gdalinfo {path_subset_tif}').split('\n')]
diff = ''.join(list(unified_diff(gdalinfo_orig[2:], gdalinfo_out[2:])))
self.assertFalse(diff)
self.assertFalse(diff,
f'\n\nThe gdalinfo output of the saved dataset contains some unexpected differences: \n\n'
f'{diff}')
# os.system(f'gdalinfo {p_out}')
def test_show(self):
......
Supports Markdown
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