diff --git a/CHANGELOG.md b/CHANGELOG.md index e301836bd..c8c973a67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Code freeze date: YYYY-MM-DD ### Fixed - Fixed asset count in impact logging message [#1195](https://github.com/CLIMADA-project/climada_python/pull/1195). +- `Hazard.from_raster_xarray` now returns a sparse matrix instead of a sparse array [#1261](https://github.com/CLIMADA-project/climada_python/pull/1261). ### Deprecated diff --git a/climada/hazard/test/test_xarray.py b/climada/hazard/test/test_xarray.py index b20f7ab05..3e3e0799c 100644 --- a/climada/hazard/test/test_xarray.py +++ b/climada/hazard/test/test_xarray.py @@ -28,7 +28,7 @@ import numpy as np import xarray as xr from pyproj import CRS -from scipy.sparse import csr_array, csr_matrix +from scipy.sparse import csr_matrix from climada.hazard.base import Hazard from climada.util.constants import DEF_CRS @@ -104,8 +104,8 @@ def _assert_default_types(self, hazard): self.assertIsInstance(hazard.event_id, np.ndarray) self.assertIsInstance(hazard.event_name, list) self.assertIsInstance(hazard.frequency, np.ndarray) - self.assertIsInstance(hazard.intensity, csr_matrix | csr_array) - self.assertIsInstance(hazard.fraction, csr_matrix | csr_array) + self.assertIsInstance(hazard.intensity, csr_matrix) + self.assertIsInstance(hazard.fraction, csr_matrix) self.assertIsInstance(hazard.date, np.ndarray) def test_load_path(self): diff --git a/climada/hazard/xarray.py b/climada/hazard/xarray.py index 167fdad6a..95b20eee5 100644 --- a/climada/hazard/xarray.py +++ b/climada/hazard/xarray.py @@ -58,7 +58,9 @@ def _to_csr_matrix(array: xr.DataArray) -> sparse.csr_matrix: output_dtypes=[array.dtype], ) sparse_coo = array.compute().data # Load into memory - return sparse_coo.tocsr() # Convert sparse.COO to scipy.sparse.csr_array + return sparse.csr_matrix( + sparse_coo.tocsr() + ) # Convert sparse.COO to scipy.sparse.csr_matrix # Define accessors for xarray DataArrays