corteva / rioxarray

geospatial xarray extension powered by rasterio
https://corteva.github.io/rioxarray
Other
517 stars 81 forks source link

Incompatibility with numpy updates #779

Closed MelissaLatellaCMCC closed 3 months ago

MelissaLatellaCMCC commented 3 months ago

When I import rioxarray this issue arises:

AttributeError: module 'numpy' has no attribute 'float'. np.float was a deprecated alias for the builtin float. To avoid this error in existing code, use float by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.float64 here. The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

snowman2 commented 3 months ago

Would you mind providing:

MelissaLatellaCMCC commented 3 months ago

The versions are: Python 3.12.3 rioxarray 0.15.5

The error came out of the blue, from one day to another. In the meantime, I installed ee and geetools.

Here is the traceback:

AttributeError Traceback (most recent call last) Cell In[1], line 6 4 from datetime import datetime 5 import geopandas as gpd ----> 6 import rioxarray 7 from rasterio.enums import Resampling 8 from shapely.geometry import Polygon

File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\rioxarray__init__.py:5 2 author = """rioxarray Contributors""" 3 import importlib.metadata ----> 5 import rioxarray.raster_array # noqa 6 import rioxarray.raster_dataset # noqa 7 from rioxarray._io import open_rasterio

File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\rioxarray\raster_array.py:38 31 from rioxarray.crs import crs_from_user_input 32 from rioxarray.exceptions import ( 33 MissingCRS, 34 NoDataInBounds, 35 OneDimensionalRaster, 36 RioXarrayError, 37 ) ---> 38 from rioxarray.raster_writer import RasterioWriter, _ensure_nodata_dtype 39 from rioxarray.rioxarray import ( 40 XRasterBase, 41 _get_data_var_message, 42 _make_coords, 43 _order_bounds, 44 ) 46 # DTYPE TO NODATA MAP 47 # Based on: https://github.com/OSGeo/gdal/blob/ 48 # dee861e7c91c2da7ef8ff849947713e4d9bd115c/ 49 # swig/python/gdal-utils/osgeo_utils/gdal_calc.py#L61

File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\rioxarray\raster_writer.py:22 19 from rioxarray.exceptions import RioXarrayError 21 try: ---> 22 import dask.array 23 from dask import is_dask_collection 24 except ImportError:

File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\dask\array__init__.py:3 1 try: 2 from .blockwise import blockwise, atop ----> 3 from .core import ( 4 Array, 5 block, 6 concatenate, 7 stack, 8 from_array, 9 store, 10 map_blocks, 11 to_hdf5, 12 to_npy_stack, 13 from_npy_stack, 14 from_delayed, 15 asarray, 16 asanyarray, 17 PerformanceWarning, 18 broadcast_arrays, 19 broadcast_to, 20 from_zarr, 21 to_zarr, 22 unify_chunks, 23 ) 24 from .tiledb_io import from_tiledb, to_tiledb 25 from .numpy_compat import rollaxis, moveaxis

File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\dask\array\core.py:22 19 from tlz.curried import pluck 20 import numpy as np ---> 22 from . import chunk 23 from .. import config, compute 24 from ..base import ( 25 DaskMethodsMixin, 26 tokenize, (...) 30 is_dask_collection, 31 )

File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\dask\array\chunk.py:7 5 from tlz import concat 6 import numpy as np ----> 7 from . import numpy_compat as npcompat 9 from ..core import flatten 10 from ..utils import ignoring

File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\dask\array\numpy_compat.py:21 16 try: 17 with warnings.catch_warnings(): 18 if ( 19 not np.allclose( 20 np.divide(0.4, 1, casting="unsafe"), ---> 21 np.divide(0.4, 1, casting="unsafe", dtype=np.float), 22 ) 23 or not np.allclose(np.divide(1, 0.5, dtype="i8"), 2) 24 or not np.allclose(np.divide(0.4, 1), 0.4) 25 ): 26 raise TypeError( 27 "Divide not working with dtype: " 28 "https://github.com/numpy/numpy/issues/3484" 29 ) 30 divide = np.divide

File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\numpy__init.py:338, in getattr(attr) 333 warnings.warn( 334 f"In the future np.{attr} will be defined as the " 335 "corresponding NumPy scalar.", FutureWarning, stacklevel=2) 337 if attr in former_attrs: --> 338 raise AttributeError(former_attrs__[attr]) 340 if attr == 'testing': 341 import numpy.testing as testing

AttributeError: module 'numpy' has no attribute 'float'. np.float was a deprecated alias for the builtin float. To avoid this error in existing code, use float by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.float64 here. The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

snowman2 commented 3 months ago

The error is originating from dask. It looks like they have solved some issues: https://github.com/dask/dask/issues/11066. If the issue you are seeing has not been addressed by their fixes, I recommend opening an issue there.