Skip to content

Commit

Permalink
Support NumPy 2.0 can_cast (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
floriandeboissieu authored Aug 9, 2024
1 parent 95fa740 commit 57d2d45
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 40 deletions.
119 changes: 82 additions & 37 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies = [
"pyproj<4.0.0,>=3.0.0",
"rasterio<2.0.0,>=1.3.0",
"xarray>=0.18",
"numpy<3,>1.23",
]
description = "Load a STAC collection into xarray with dask"
license = {text = "MIT"}
Expand Down
4 changes: 2 additions & 2 deletions stackstac/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def prepare_items(
asset_offset = 0

if rescale:
if not np.can_cast(asset_scale, dtype):
if not np.can_cast(type(asset_scale), dtype):
raise ValueError(
f"`rescale=True`, but safe casting cannot be completed between "
f"asset scale value {asset_scale} and output dtype {dtype}.\n"
Expand All @@ -174,7 +174,7 @@ def prepare_items(
"values, pass a different `dtype=` (typically `float`)."
)

if not np.can_cast(asset_offset, dtype):
if not np.can_cast(type(asset_offset), dtype):
raise ValueError(
f"`rescale=True`, but safe casting cannot be completed between "
f"asset offset value {asset_offset} and output dtype {dtype}.\n"
Expand Down
2 changes: 1 addition & 1 deletion stackstac/to_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def items_to_dask(
"Create a dask Array from an asset table"
errors_as_nodata = errors_as_nodata or () # be sure it's not None

if not np.can_cast(fill_value, dtype):
if not np.can_cast(type(fill_value), dtype):
raise ValueError(
f"The fill_value {fill_value} is incompatible with the output dtype {dtype}. "
f"Either use `dtype={np.array(fill_value).dtype.name!r}`, or pick a different `fill_value`."
Expand Down

0 comments on commit 57d2d45

Please sign in to comment.