From 276e0513d9f65b375e6047da852d3612229a911f Mon Sep 17 00:00:00 2001 From: Joshua Larsen Date: Tue, 9 Aug 2022 06:13:37 -0700 Subject: [PATCH 1/4] update(intersect): update warning to raise error only when interface is called improperly --- flopy/discretization/grid.py | 8 +++++++- flopy/discretization/structuredgrid.py | 7 ++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/flopy/discretization/grid.py b/flopy/discretization/grid.py index 80d259e468..de66e32b06 100644 --- a/flopy/discretization/grid.py +++ b/flopy/discretization/grid.py @@ -680,6 +680,11 @@ def _warn_intersect(self, module, lineno): Should be be removed after a couple of releases. Added in 3.3.5 + Updated in 3.3.6 to raise an error and exit if intersect interface + is called incorrectly. + + Should be removed in flopy 3.3.7 + Parameters ---------- module : str @@ -698,7 +703,8 @@ def _warn_intersect(self, module, lineno): "intersect(self, x, y, z=None, local=False, " "forgive=False) interface instead." ) - warnings.warn_explicit(warning, UserWarning, module, lineno) + + raise UserWarning(warning) def set_coord_info( self, diff --git a/flopy/discretization/structuredgrid.py b/flopy/discretization/structuredgrid.py index e923b7d521..ba42de2ee5 100644 --- a/flopy/discretization/structuredgrid.py +++ b/flopy/discretization/structuredgrid.py @@ -773,9 +773,10 @@ def intersect(self, x, y, z=None, local=False, forgive=False): The column number """ - # trigger interface change warning - frame_info = inspect.getframeinfo(inspect.currentframe()) - self._warn_intersect(frame_info.filename, frame_info.lineno) + if isinstance(z, bool): + # trigger interface change warning + frame_info = inspect.getframeinfo(inspect.currentframe()) + self._warn_intersect(frame_info.filename, frame_info.lineno) # transform x and y to local coordinates x, y = super().intersect(x, y, local, forgive) From 65bf88dd232a26cbe3b641ed45bcdfedf9372daf Mon Sep 17 00:00:00 2001 From: Joshua Larsen Date: Tue, 9 Aug 2022 06:30:43 -0700 Subject: [PATCH 2/4] update(intersect): update VertexGrid and UnstructuredGrid intersect routines --- flopy/discretization/unstructuredgrid.py | 5 +++-- flopy/discretization/vertexgrid.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/flopy/discretization/unstructuredgrid.py b/flopy/discretization/unstructuredgrid.py index 902cf3995f..739230fa85 100644 --- a/flopy/discretization/unstructuredgrid.py +++ b/flopy/discretization/unstructuredgrid.py @@ -538,8 +538,9 @@ def intersect(self, x, y, z=None, local=False, forgive=False): The CELL2D number """ - frame_info = inspect.getframeinfo(inspect.currentframe()) - self._warn_intersect(frame_info.filename, frame_info.lineno) + if instance(z, bool): + frame_info = inspect.getframeinfo(inspect.currentframe()) + self._warn_intersect(frame_info.filename, frame_info.lineno) if local: # transform x and y to real-world coordinates diff --git a/flopy/discretization/vertexgrid.py b/flopy/discretization/vertexgrid.py index 251a14db1b..9ee51a0caa 100644 --- a/flopy/discretization/vertexgrid.py +++ b/flopy/discretization/vertexgrid.py @@ -283,8 +283,9 @@ def intersect(self, x, y, z=None, local=False, forgive=False): The CELL2D number """ - frame_info = inspect.getframeinfo(inspect.currentframe()) - self._warn_intersect(frame_info.filename, frame_info.lineno) + if isinstance(z, bool): + frame_info = inspect.getframeinfo(inspect.currentframe()) + self._warn_intersect(frame_info.filename, frame_info.lineno) if local: # transform x and y to real-world coordinates From af1ecf8ce352de0c3c9bac17d834dca410ca4c33 Mon Sep 17 00:00:00 2001 From: Joshua Larsen Date: Tue, 9 Aug 2022 07:05:39 -0700 Subject: [PATCH 3/4] fix typo --- flopy/discretization/unstructuredgrid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flopy/discretization/unstructuredgrid.py b/flopy/discretization/unstructuredgrid.py index 739230fa85..329718f2c3 100644 --- a/flopy/discretization/unstructuredgrid.py +++ b/flopy/discretization/unstructuredgrid.py @@ -538,7 +538,7 @@ def intersect(self, x, y, z=None, local=False, forgive=False): The CELL2D number """ - if instance(z, bool): + if isinstance(z, bool): frame_info = inspect.getframeinfo(inspect.currentframe()) self._warn_intersect(frame_info.filename, frame_info.lineno) From a45dd784dc289486f444a5cbcf7b45ea570f8dd7 Mon Sep 17 00:00:00 2001 From: Joshua Larsen Date: Tue, 9 Aug 2022 07:39:21 -0700 Subject: [PATCH 4/4] remove "flopy" from hashFiles call --- .github/workflows/commit.yml | 2 +- .github/workflows/daily.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/commit.yml b/.github/workflows/commit.yml index 9264d2ac10..569e4ab2dd 100644 --- a/.github/workflows/commit.yml +++ b/.github/workflows/commit.yml @@ -302,7 +302,7 @@ jobs: uses: actions/cache@v2.1.0 with: path: ~/conda_pkgs_dir - key: ${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.run-type }}-${{ hashFiles('etc/environment.yml', 'flopy') }} + key: ${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.run-type }}-${{ hashFiles('etc/environment.yml') }} # Standard python fails on windows without GDAL installation # Using custom bash shell ("shell: bash -l {0}") with Miniconda diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml index 7015e65f18..eb624e4a83 100644 --- a/.github/workflows/daily.yml +++ b/.github/workflows/daily.yml @@ -291,7 +291,7 @@ jobs: uses: actions/cache@v2.1.0 with: path: ~/conda_pkgs_dir - key: ${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.run-type }}-${{ hashFiles('etc/environment.yml', 'flopy') }} + key: ${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.run-type }}-${{ hashFiles('etc/environment.yml') }} # Standard python fails on windows without GDAL installation # Using custom bash shell ("shell: bash -l {0}") with Miniconda