@@ -42,7 +42,7 @@ def _curthread():
42
42
open = dict (
43
43
GDAL_DISABLE_READDIR_ON_OPEN = "EMPTY_DIR" ,
44
44
# ^ stop GDAL from requesting `.aux` and `.msk` files from the bucket (speeds up `open` time a lot)
45
- VSI_CACHE = True
45
+ VSI_CACHE = True ,
46
46
# ^ cache HTTP requests for opening datasets. This is critical for `ThreadLocalRioDataset`,
47
47
# which re-opens the same URL many times---having the request cached makes subsequent `open`s
48
48
# in different threads snappy.
@@ -70,11 +70,9 @@ def _curthread():
70
70
class ThreadsafeRioDataset (Protocol ):
71
71
scale_offset : Tuple [Union [int , float ], Union [int , float ]]
72
72
73
- def read (self , window : Window , ** kwargs ) -> np .ndarray :
74
- ...
73
+ def read (self , window : Window , ** kwargs ) -> np .ndarray : ...
75
74
76
- def close (self ) -> None :
77
- ...
75
+ def close (self ) -> None : ...
78
76
79
77
80
78
class SingleThreadedRioDataset :
@@ -408,8 +406,14 @@ def read(self, window: Window, **kwargs) -> np.ndarray:
408
406
result = np .ma .masked_array (result [0 ], mask = result [1 ] == 0 )
409
407
elif result .shape [0 ] == 1 :
410
408
result = result [0 ]
411
- else :
412
- raise RuntimeError (f"Unexpected shape { result .shape } , expected exactly 1 band." )
409
+ elif result .ndim != 2 :
410
+ # We should only be getting `result.ndim == 2` in the case when `_open` produced a `NodataReader`.
411
+ # `Reader`s always return 2D arrays, whereas `rasterio.read` returns 3D. Pedantically, `NodataReader`
412
+ # shouldn't be a `Reader`, but a `ThreadsafeRioDataset`, and it should return a 3D array,
413
+ # just to be more consistent.
414
+ raise RuntimeError (
415
+ f"Unexpected shape { result .shape } , expected exactly 1 band."
416
+ )
413
417
414
418
scale , offset = self .scale_offset
415
419
@@ -419,9 +423,9 @@ def read(self, window: Window, **kwargs) -> np.ndarray:
419
423
result += offset
420
424
421
425
result = np .ma .filled (result , fill_value = self .fill_value )
422
- assert np .issubdtype (result . dtype , self . dtype ), (
423
- f"Expected result array with dtype { self .dtype !r } , got { result .dtype !r } "
424
- )
426
+ assert np .issubdtype (
427
+ result .dtype , self .dtype
428
+ ), f"Expected result array with dtype { self . dtype !r } , got { result . dtype !r } "
425
429
return result
426
430
427
431
def close (self ) -> None :
0 commit comments