From c463b9155f4657877da0a5868db6752b02eb8881 Mon Sep 17 00:00:00 2001 From: ljwolf Date: Tue, 27 Jul 2021 11:22:08 +0100 Subject: [PATCH 1/2] add pygeos-tolerant fails for the module --- esda/__init__.py | 2 +- esda/map_comparison.py | 14 +++++++++++++- esda/shape.py | 11 ++++++++--- 3 files changed, 22 insertions(+), 5 deletions(-) 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..3b82d9cd 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: + 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..9ac6d96c 100644 --- a/esda/shape.py +++ b/esda/shape.py @@ -1,13 +1,18 @@ -import pygeos -import geopandas, pandas import numpy -from numba import njit, prange +import pandas +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(): From 56dd51120a9b2345255b79ace87173f00b864e86 Mon Sep 17 00:00:00 2001 From: ljwolf Date: Tue, 27 Jul 2021 12:36:59 +0100 Subject: [PATCH 2/2] also add try/except outside of cast --- esda/map_comparison.py | 2 +- esda/shape.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/esda/map_comparison.py b/esda/map_comparison.py index 3b82d9cd..99eccf76 100644 --- a/esda/map_comparison.py +++ b/esda/map_comparison.py @@ -3,7 +3,7 @@ try: import pygeos -except: +except (ImportError, ModuleNotFoundError): pass # gets handled in the _cast function. # from nowosad and stepinski diff --git a/esda/shape.py b/esda/shape.py index 9ac6d96c..0e03a411 100644 --- a/esda/shape.py +++ b/esda/shape.py @@ -1,5 +1,11 @@ import numpy import pandas + +try: + import pygeos +except (ImportError, ModuleNotFoundError): + pass # gets handled at the _cast level. + from .crand import njit, prange