opendatacube / odc-stac

Load STAC items into xarray Datasets.
Apache License 2.0
140 stars 20 forks source link

Import Error When Running `odc.stac` on Colab #164

Open CristinaMarsh opened 4 months ago

CristinaMarsh commented 4 months ago

Hi there,

I hope this message finds you well. I encountered an issue while trying to use odc.stac in Google Colab. It seems there's an import error related to dask.typing. Below is the code snippet and the full traceback of the error:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/tmp/ipykernel_12981/1875870462.py in <cell line: 3>()
      1 import geopandas as gpd
      2 import json
----> 3 from odc.stac import stac_load
      4 
      5 # # Define the bounding box for Beijing

2 frames
/usr/local/lib/python3.10/dist-packages/odc/loader/_builder.py in <module>
     30 from dask.base import quote, tokenize
     31 from dask.highlevelgraph import HighLevelGraph
---> 32 from dask.typing import Key
     33 from numpy.typing import DTypeLike
     34 from odc.geo.geobox import GeoBox, GeoBoxBase, GeoboxTiles

ImportError: cannot import name 'Key' from 'dask.typing' (/usr/local/lib/python3.10/dist-packages/dask/typing.py)

It appears that there might be an issue with the compatibility between odc.stac and the current version of dask being used. Any guidance on resolving this issue or updating the package to be compatible with the latest versions of dask would be greatly appreciated.

Thank you very much for your time and assistance!

Kirill888 commented 4 months ago

looks like the real issue is that we started using dask.typing.Key but have not updated minimal bound on dask. This was added to dask with https://github.com/dask/dask/pull/10485

Not sure what version of Dask is in colab, but it's not latest, latest one should have it. You should be able to update dask to a more recent version, or alternatively downgrade odc-stac.

Work item for odc-stac is to figure out oldest version of Dask that has dask.typing.Key available and update dask bounds here:

https://github.com/opendatacube/odc-stac/blob/cf7b897eadd352d46c96ba80625a7a94e9823b6f/setup.cfg#L43

and also on conda-forge. I don't think we can afford supporting old versions of Dask, error is in packaging and should be fixed there.

CristinaMarsh commented 4 months ago

looks like the real issue is that we started using dask.typing.Key but have not updated minimal bound on dask. This was added to dask with dask/dask#10485

Not sure what version of Dask is in colab, but it's not latest, latest one should have it. You should be able to update dask to a more recent version, or alternatively downgrade odc-stac.

Work item for odc-stac is to figure out oldest version of Dask that has dask.typing.Key available and update dask bounds here:

https://github.com/opendatacube/odc-stac/blob/cf7b897eadd352d46c96ba80625a7a94e9823b6f/setup.cfg#L43

and also on conda-forge. I don't think we can afford supporting old versions of Dask, error is in packaging and should be fixed there.

Thank you! Your suggestion to upgrade Dask was spot on! I updated Dask to the latest version (dask-2024.7.0), and it resolved the problem perfectly.