gjoseph92 / stackstac

Turn a STAC catalog into a dask-based xarray
https://stackstac.readthedocs.io
MIT License
232 stars 49 forks source link

can_cast throws error with numpy 2.0.0 #250

Open floriandeboissieu opened 1 month ago

floriandeboissieu commented 1 month ago

With new version of numpy v2.0.0, np.can_cast does not accept ints, float or complex anymore. Thus stackstac.stack raise an error systematically, example:

import stackstac
import pystac_client

URL = "https://earth-search.aws.element84.com/v1"
catalog = pystac_client.Client.open(URL)

stac_items = catalog.search(
    intersects=dict(type="Point", coordinates=[-105.78, 35.79]),
    collections=["sentinel-2-l2a"],
    datetime="2020-04-01/2020-05-01"
).get_all_items()

stack = stackstac.stack(stac_items)

returns:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\gitlab_runner\miniforge3\envs\fordead-gitlab-ci\Lib\site-packages\stackstac\stack.py", line 290, in stack
    asset_table, spec, asset_ids, plain_items = prepare_items(
                                                ^^^^^^^^^^^^^^
  File "C:\Users\gitlab_runner\miniforge3\envs\fordead-gitlab-ci\Lib\site-packages\stackstac\prepare.py", line 168, in prepare_items
    if not np.can_cast(asset_scale, dtype):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: can_cast() does not support Python ints, floats, and complex because the result used to depend on the value.
This change was part of adopting NEP 50, we may explicitly allow them again in the future.