Skip to content

can_cast throws error with numpy 2.0.0 #250

@floriandeboissieu

Description

@floriandeboissieu

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions