From 4e1c6f4b1717706d5b9c7df9b4a3c08a425bc3de Mon Sep 17 00:00:00 2001 From: Romain Hugonnet Date: Wed, 13 Mar 2024 10:20:58 -0800 Subject: [PATCH] Remove optional import for `rioxarray` (#514) --- geoutils/raster/raster.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/geoutils/raster/raster.py b/geoutils/raster/raster.py index 1d092276..a886b0a9 100644 --- a/geoutils/raster/raster.py +++ b/geoutils/raster/raster.py @@ -21,6 +21,8 @@ import rasterio as rio import rasterio.warp import rasterio.windows +import rioxarray +import xarray as xr from affine import Affine from mpl_toolkits.axes_grid1 import make_axes_locatable from rasterio.crs import CRS @@ -54,15 +56,6 @@ except ImportError: from typing_extensions import Literal # type: ignore -try: - import rioxarray - import xarray as xr - - _has_rioxarray = True -except ImportError: - rioxarray = None - _has_rioxarray = False - RasterType = TypeVar("RasterType", bound="Raster") # List of NumPy "array" functions that are handled. @@ -2650,8 +2643,6 @@ def to_xarray(self, name: str | None = None) -> xr.DataArray: :returns: xarray DataArray """ - if not _has_rioxarray: - raise ImportError("rioxarray is required for this functionality.") ds = rioxarray.open_rasterio(self.to_rio_dataset()) if name is not None: