Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch some mosaic usage errors with nodata=nan #123

Merged
merged 2 commits into from
Jan 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions stackstac/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,21 @@ def mosaic(
nodata:
The value to treat as invalid. Default: NaN.

To catch common mis-use, raises a ``ValueError`` if ``nodata=nan``
is used when the array has an integer or boolean dtype. Since NaN
cannot exist in those arrays, this indicates a different ``nodata``
value needs to be used.

Returns
-------
xarray.DataArray:
The mosaicked `~xarray.DataArray`.
"""
if np.isnan(nodata) and arr.dtype.kind in "biu":
# Try to catch usage errors forgetting to set `nodata=`
raise ValueError(
f"Cannot use {nodata=} when mosaicing a {arr.dtype} array, since {nodata} cannot exist in the array."
)
return arr.reduce(
_mosaic,
dim=dim,
Expand Down