@@ -24,18 +24,12 @@ def items_to_dask(
2424 chunksize : int ,
2525 resampling : Resampling = Resampling .nearest ,
2626 dtype : np .dtype = np .dtype ("float64" ),
27- fill_value : Optional [ Union [int , float ] ] = np .nan ,
27+ fill_value : Union [int , float ] = np .nan ,
2828 rescale : bool = True ,
2929 reader : Type [Reader ] = AutoParallelRioReader ,
3030 gdal_env : Optional [LayeredEnv ] = None ,
3131 errors_as_nodata : Tuple [Exception , ...] = (),
3232) -> da .Array :
33- if fill_value is None and errors_as_nodata :
34- raise ValueError (
35- "A non-None `fill_value` is required when using `errors_as_nodata`. "
36- "If an exception occurs, we need to know what to use as the nodata value, "
37- "since there may not be an open dataset to infer it from."
38- )
3933 errors_as_nodata = errors_as_nodata or () # be sure it's not None
4034
4135 if fill_value is not None and not np .can_cast (fill_value , dtype ):
@@ -114,17 +108,18 @@ def asset_entry_to_reader_and_window(
114108 spec : RasterSpec ,
115109 resampling : Resampling ,
116110 dtype : np .dtype ,
117- fill_value : Optional [ Union [int , float ] ],
111+ fill_value : Union [int , float ],
118112 rescale : bool ,
119113 gdal_env : Optional [LayeredEnv ],
120114 errors_as_nodata : Tuple [Exception , ...],
121115 reader : Type [ReaderT ],
122- ) -> Optional [ Tuple [ReaderT , windows .Window ]] :
116+ ) -> Tuple [ReaderT , windows .Window ] | np . ndarray :
123117 asset_entry = asset_entry [0 , 0 ]
124118 # ^ because dask adds extra outer dims in `from_array`
125119 url = asset_entry ["url" ]
126120 if url is None :
127- return None
121+ # Signifies empty value
122+ return np .array (fill_value , dtype )
128123
129124 asset_bounds : Bbox = asset_entry ["bounds" ]
130125 asset_window = windows .from_bounds (* asset_bounds , transform = spec .transform )
@@ -159,11 +154,11 @@ def asset_entry_to_reader_and_window(
159154
160155
161156def fetch_raster_window (
162- asset_entry : Optional [ Tuple [Reader , windows .Window ]] ,
157+ asset_entry : Tuple [ReaderT , windows .Window ] | np . ndarray ,
163158 slices : Tuple [slice , ...],
164159) -> np .ndarray :
165160 current_window = windows .Window .from_slices (* slices )
166- if asset_entry is not None :
161+ if isinstance ( asset_entry , tuple ) :
167162 reader , asset_window = asset_entry
168163
169164 # check that the window we're fetching overlaps with the asset
@@ -172,7 +167,11 @@ def fetch_raster_window(
172167 data = reader .read (current_window )
173168
174169 return data [None , None ]
170+ fill_arr = np .array (reader .fill_value , reader .dtype )
171+ else :
172+ fill_arr : np .ndarray = asset_entry
175173
176174 # no dataset, or we didn't overlap it: return empty data.
177175 # use the broadcast trick for even fewer memz
178- return np .broadcast_to (np .nan , (1 , 1 ) + windows .shape (current_window ))
176+ return np .broadcast_to (fill_arr , (1 , 1 ) + windows .shape (current_window ))
177+
0 commit comments