return tuples, not lists from DatasetReader

This commit is contained in:
Matthew Perry 2016-04-11 11:34:14 -04:00
parent e94bdb7738
commit 7b4118a84b
7 changed files with 17 additions and 17 deletions

View File

@ -282,11 +282,11 @@ cdef class DatasetReader(object):
@property
def indexes(self):
return list(range(1, self.count+1))
return tuple(range(1, self.count+1))
@property
def dtypes(self):
"""Returns an ordered list of all band data types."""
"""Returns an ordered tuple of all band data types."""
cdef void *hband = NULL
if not self._dtypes:
if self._hds == NULL:
@ -295,7 +295,7 @@ cdef class DatasetReader(object):
hband = _gdal.GDALGetRasterBand(self._hds, i+1)
self._dtypes.append(
dtypes.dtype_fwd[_gdal.GDALGetRasterDataType(hband)])
return self._dtypes
return tuple(self._dtypes)
@property
def block_shapes(self):
@ -316,7 +316,7 @@ cdef class DatasetReader(object):
raise ValueError("Null band")
_gdal.GDALGetBlockSize(hband, &xsize, &ysize)
self._block_shapes.append((ysize, xsize))
return self._block_shapes
return tuple(self._block_shapes)
def get_nodatavals(self):
cdef void *hband = NULL
@ -347,7 +347,7 @@ cdef class DatasetReader(object):
log.debug("Nodata value: %f", nodataval)
self._nodatavals.append(val)
return self._nodatavals
return tuple(self._nodatavals)
property nodatavals:
"""Nodata values for each band."""

View File

@ -69,7 +69,7 @@ class RasterBlocksTest(unittest.TestCase):
def test_blocks(self):
with rasterio.open('tests/data/RGB.byte.tif') as s:
self.assertEqual(len(s.block_shapes), 3)
self.assertEqual(s.block_shapes, [(3, 791), (3, 791), (3, 791)])
self.assertEqual(s.block_shapes, ((3, 791), (3, 791), (3, 791)))
windows = s.block_windows(1)
(j,i), first = next(windows)
self.assertEqual((j,i), (0, 0))

View File

@ -15,7 +15,7 @@ def test_nodata(tmpdir):
with rasterio.open(dst_path, 'w', **src.meta) as dst:
assert dst.nodata == 0.0
assert dst.meta['nodata'] == 0.0
assert dst.nodatavals == [0.0, 0.0, 0.0]
assert dst.nodatavals == (0.0, 0.0, 0.0)
info = subprocess.check_output([
'gdalinfo', dst_path])
pattern = b'Band 1.*?NoData Value=0'
@ -34,7 +34,7 @@ def test_set_nodata(tmpdir):
with rasterio.open(dst_path, 'w', **meta) as dst:
assert dst.nodata == 42
assert dst.meta['nodata'] == 42
assert dst.nodatavals == [42, 42, 42]
assert dst.nodatavals == (42, 42, 42)
info = subprocess.check_output([
'gdalinfo', dst_path])
pattern = b'Band 1.*?NoData Value=42'

View File

@ -22,9 +22,9 @@ class ReaderContextTest(unittest.TestCase):
self.assertEqual(s.width, 791)
self.assertEqual(s.height, 718)
self.assertEqual(s.shape, (718, 791))
self.assertEqual(s.dtypes, [rasterio.ubyte]*3)
self.assertEqual(s.nodatavals, [0]*3)
self.assertEqual(s.indexes, [1,2,3])
self.assertEqual(s.dtypes, tuple([rasterio.ubyte] * 3))
self.assertEqual(s.nodatavals, (0, 0, 0))
self.assertEqual(s.indexes, (1, 2, 3))
self.assertEqual(s.crs['init'], 'epsg:32618')
self.assert_(s.crs_wkt.startswith('PROJCS'), s.crs_wkt)
for i, v in enumerate((101985.0, 2611485.0, 339315.0, 2826915.0)):
@ -44,8 +44,8 @@ class ReaderContextTest(unittest.TestCase):
self.assertEqual(s.width, 791)
self.assertEqual(s.height, 718)
self.assertEqual(s.shape, (718, 791))
self.assertEqual(s.dtypes, [rasterio.ubyte]*3)
self.assertEqual(s.nodatavals, [0]*3)
self.assertEqual(s.dtypes, tuple([rasterio.ubyte] * 3))
self.assertEqual(s.nodatavals, (0, 0, 0))
self.assertEqual(s.crs['init'], 'epsg:32618')
self.assertEqual(
s.affine,

View File

@ -111,7 +111,7 @@ def test_dtype(tmpdir):
['tests/data/RGB.byte.tif', outputname, '--dtype', 'uint16'])
assert result.exit_code == 0
with rasterio.open(outputname) as src:
assert src.dtypes == ['uint16'] * 3
assert src.dtypes == tuple(['uint16'] * 3)
def test_dtype_rescaling_uint8_full(tmpdir):

View File

@ -58,7 +58,7 @@ def test_update_nodatavals(data):
with rasterio.open(tiffname, 'r+') as f:
f.nodata = 255
with rasterio.open(tiffname) as f:
assert f.nodatavals == [255, 255, 255]
assert f.nodatavals == (255, 255, 255)
def test_update_nodatavals_error(data):

View File

@ -61,7 +61,7 @@ def test_context(tmpdir):
assert s.width == 100
assert s.height == 100
assert s.shape == (100, 100)
assert s.indexes == [1]
assert s.indexes == (1,)
assert repr(s) == "<open RasterUpdater name='%s' mode='w'>" % name
assert s.closed == True
assert s.count == 1
@ -122,7 +122,7 @@ def test_write_float(tmpdir):
name, 'w',
driver='GTiff', width=100, height=100, count=2,
dtype=rasterio.float32) as s:
assert s.dtypes == [rasterio.float32]*2
assert s.dtypes == (rasterio.float32, rasterio.float32)
s.write_band(1, a)
s.write_band(2, a)
info = subprocess.check_output(["gdalinfo", "-stats", name]).decode('utf-8')