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

Add dtype validation when rescale=True #209

Merged
merged 13 commits into from
Sep 19, 2023
4 changes: 4 additions & 0 deletions stackstac/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ def stack(
The size of ``y`` and ``x`` will be determined by ``resolution`` and ``bounds``, which in many cases are
automatically computed from the items you pass in.
"""
if rescale:
assert "float" in np.dtype(dtype).name, "The requested dtype is incompatible with rescale=True, which requires a floating-point dtype."
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert "float" in np.dtype(dtype).name, "The requested dtype is incompatible with rescale=True, which requires a floating-point dtype."
assert np.dtype(dtype).kind in ("f", "c"), "The requested dtype is incompatible with rescale=True, which requires a floating-point dtype."

nit: using dtype.kind is probably the more proper way to write this test. Also, complex floats would be valid too (could come up for SAR data).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I was searching for a good way to do this and could not find one, this is handy.


plain_items = items_to_plain(items)

if sortby_date is not False:
Expand All @@ -294,6 +297,7 @@ def stack(
bounds_latlon=bounds_latlon,
snap_bounds=snap_bounds,
)

arr = items_to_dask(
asset_table,
spec,
Expand Down