diff --git a/esda/__init__.py b/esda/__init__.py index d05aac65..b9e5c417 100644 --- a/esda/__init__.py +++ b/esda/__init__.py @@ -1,4 +1,4 @@ -__version__ = "2.4.0" +__version__ = "2.4.1" """ :mod:`esda` --- Exploratory Spatial Data Analysis ================================================= diff --git a/esda/map_comparison.py b/esda/map_comparison.py index 23a01b4e..99eccf76 100644 --- a/esda/map_comparison.py +++ b/esda/map_comparison.py @@ -1,6 +1,11 @@ -import numpy, pygeos, pandas, geopandas +import numpy, pandas from scipy.special import entr +try: + import pygeos +except (ImportError, ModuleNotFoundError): + pass # gets handled in the _cast function. + # from nowosad and stepinski # https://doi.org/10.1080/13658816.2018.1511794 @@ -21,6 +26,13 @@ def _cast(collection): """ Cast a collection to a pygeos geometry array. """ + try: + import pygeos, geopandas + except (ImportError, ModuleNotFoundError) as exception: + raise type(exception)( + "pygeos and geopandas are required for map comparison statistics." + ) + if isinstance(collection, (geopandas.GeoSeries, geopandas.GeoDataFrame)): return collection.geometry.values.data.squeeze() elif pygeos.is_geometry(collection).all(): diff --git a/esda/shape.py b/esda/shape.py index 096cb116..0e03a411 100644 --- a/esda/shape.py +++ b/esda/shape.py @@ -1,13 +1,24 @@ -import pygeos -import geopandas, pandas import numpy -from numba import njit, prange +import pandas + +try: + import pygeos +except (ImportError, ModuleNotFoundError): + pass # gets handled at the _cast level. + +from .crand import njit, prange + # -------------------- UTILITIES --------------------# def _cast(collection): """ Cast a collection to a pygeos geometry array. """ + try: + import pygeos, geopandas + except (ImportError, ModuleNotFoundError) as exception: + raise type(exception)("pygeos and geopandas are required for shape statistics.") + if isinstance(collection, (geopandas.GeoSeries, geopandas.GeoDataFrame)): return collection.geometry.values.data.squeeze() elif pygeos.is_geometry(collection).all():