Skip to content

Commit

Permalink
fix(numpy): handle deprecation warnings from numpy 1.21 (#1211)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwtoews authored Aug 23, 2021
1 parent a267d15 commit 8ec8d09
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions flopy/utils/gridintersect.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,54 @@
import warnings
from distutils.version import LooseVersion

NUMPY_GE_121 = str(np.__version__) >= LooseVersion("1.21")

try:
import shapely

SHAPELY_GE_20 = str(shapely.__version__) >= LooseVersion("2.0")
except:
SHAPELY_LT_18 = str(shapely.__version__) < LooseVersion("1.8")
except ImportError:
shapely = None
SHAPELY_GE_20 = False
SHAPELY_LT_18 = False

try:
from shapely.errors import ShapelyDeprecationWarning as shapely_warning
except:
except ImportError:
shapely_warning = None

if shapely_warning is not None and not SHAPELY_GE_20:

@contextlib.contextmanager
def ignore_shapely_warnings_for_object_array():
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=shapely_warning)
warnings.filterwarnings(
"ignore",
"Iteration|The array interface|__len__",
shapely_warning,
)
if NUMPY_GE_121:
# warning from numpy for existing Shapely releases (this is
# fixed with Shapely 1.8)
warnings.filterwarnings(
"ignore",
"An exception was ignored while fetching",
DeprecationWarning,
)
yield


elif SHAPELY_LT_18 and NUMPY_GE_121:

@contextlib.contextmanager
def ignore_shapely_warnings_for_object_array():
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore",
"An exception was ignored while fetching",
DeprecationWarning,
)
yield


Expand Down

0 comments on commit 8ec8d09

Please sign in to comment.