File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -45,11 +45,21 @@ def mosaic(
4545 nodata:
4646 The value to treat as invalid. Default: NaN.
4747
48+ To catch common mis-use, raises a ``ValueError`` if ``nodata=nan``
49+ is used when the array has an integer or boolean dtype. Since NaN
50+ cannot exist in those arrays, this indicates a different ``nodata``
51+ value needs to be used.
52+
4853 Returns
4954 -------
5055 xarray.DataArray:
5156 The mosaicked `~xarray.DataArray`.
5257 """
58+ if np .isnan (nodata ) and arr .dtype .kind in "biu" :
59+ # Try to catch usage errors forgetting to set `nodata=`
60+ raise ValueError (
61+ f"Cannot use { nodata = } when mosaicing a { arr .dtype } array, since { nodata } cannot exist in the array."
62+ )
5363 return arr .reduce (
5464 _mosaic ,
5565 dim = dim ,
You can’t perform that action at this time.
0 commit comments