Skip to content

Commit 376e537

Browse files
authored
zonal_stats: ensure chunksizes of zones and values are matching (#574)
1 parent 9d2ee7c commit 376e537

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

xrspatial/zonal.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,9 @@ def stats(
374374
values : xr.DataArray
375375
values is a 2D xarray DataArray of numeric values (integers or floats).
376376
The input `values` raster contains the input values used in
377-
calculating the output statistic for each zone.
377+
calculating the output statistic for each zone. In dask case,
378+
the chunksizes of `zones` and `values` should be matching. If not,
379+
`values` will be rechunked to be the same as of `zones`.
378380
379381
zone_ids : list of ints, or floats
380382
List of zones to be included in calculation. If no zone_ids provided,
@@ -519,6 +521,11 @@ def stats(
519521
)
520522
else:
521523
# dask case
524+
525+
# make sure chunksizes of `zones` and `values` are matching
526+
if zones.chunks != values.chunks:
527+
values.data = values.data.rechunk(zones.chunks)
528+
522529
stats_df = _stats_dask_numpy(
523530
zones.data,
524531
values.data,

0 commit comments

Comments
 (0)