opendatacube / odc-geo

GeoBox and geometry utilities extracted from datacube-core
https://odc-geo.readthedocs.io/en/latest/
Apache License 2.0
83 stars 15 forks source link

odc.geo.cog incompatible with Python < 3.10 #158

Closed caitlinadams closed 5 months ago

caitlinadams commented 5 months ago

I'm doing some development in Python 3.9 and just run into an issue. When importing odc.stac, I get a call back to an issue in odc.geo.cog.

As a minimum demonstration, if I run import odc.geo.cog in a Python 3.9.19, I get the following traceback:

  File "<stdin>", line 1, in <module>
  File "/Users/caitlinadams/opt/miniconda3/envs/remotesensingtools/lib/python3.9/site-packages/odc/geo/cog/__init__.py", line 1, in <module>
    from ._rio import to_cog, write_cog, write_cog_layers
  File "/Users/caitlinadams/opt/miniconda3/envs/remotesensingtools/lib/python3.9/site-packages/odc/geo/cog/_rio.py", line 87, in <module>
    xx: xr.DataArray | list[xr.DataArray],
TypeError: unsupported operand type(s) for |: 'type' and 'types.GenericAlias'

It's specifically pointing at

def _get_gdal_metadata(
    xx: xr.DataArray | list[xr.DataArray],

It looks like the | operation for Union was only introduced in Python 3.10 (https://docs.python.org/3/library/typing.html#typing.Union), but on pypi, it states that odc.geo requires Python >=3.8.

My suggestions would be either:

  1. update the requirements suggestion to Python 3.10 and higher
  2. change this line in odc.geo to use Union instead of |
SpacemanPaul commented 5 months ago

Duplicate of #153 ?

caitlinadams commented 5 months ago

Yes, it's a duplicate, my apologies!