Skip to content

Commit

Permalink
add pygeos-tolerant fails for the module
Browse files Browse the repository at this point in the history
  • Loading branch information
ljwolf committed Jul 27, 2021
1 parent 1acdb23 commit c463b91
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion esda/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.4.0"
__version__ = "2.4.1"
"""
:mod:`esda` --- Exploratory Spatial Data Analysis
=================================================
Expand Down
14 changes: 13 additions & 1 deletion esda/map_comparison.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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():
Expand Down
11 changes: 8 additions & 3 deletions esda/shape.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down

0 comments on commit c463b91

Please sign in to comment.