From 223f7976018473f6bc619197e52b5f167c870007 Mon Sep 17 00:00:00 2001 From: Mike Taves Date: Mon, 23 Aug 2021 15:38:14 +1200 Subject: [PATCH] fix(numpy): handle deprecation warnings from numpy 1.21 --- flopy/utils/gridintersect.py | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/flopy/utils/gridintersect.py b/flopy/utils/gridintersect.py index bfe70ae839..09137b9cf6 100644 --- a/flopy/utils/gridintersect.py +++ b/flopy/utils/gridintersect.py @@ -29,17 +29,21 @@ 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: @@ -47,7 +51,32 @@ @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