Skip to content

Commit

Permalink
refactor(numpy): patch modern flip function for versions older than 1…
Browse files Browse the repository at this point in the history
….15.0 (#1004)
  • Loading branch information
mwtoews authored Oct 20, 2020
1 parent 9ad6732 commit 8f3dbec
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions flopy/discretization/structuredgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@
import numpy as np
from .grid import Grid, CachedData

try:
from numpy.lib import NumpyVersion

numpy115 = NumpyVersion(np.__version__) >= "1.15.0"
except ImportError:
numpy115 = False

if not numpy115:

def flip_numpy115(m, axis=None):
"""Provide same behavior for np.flip since numpy 1.15.0."""
import numpy.core.numeric as _nx
from numpy.core.numeric import asarray

if not hasattr(m, "ndim"):
m = asarray(m)
if axis is None:
indexer = (np.s_[::-1],) * m.ndim
else:
axis = _nx.normalize_axis_tuple(axis, m.ndim)
indexer = [np.s_[:]] * m.ndim
for ax in axis:
indexer[ax] = np.s_[::-1]
indexer = tuple(indexer)
return m[indexer]

np.flip = flip_numpy115


def array_at_verts_basic2d(a):
"""
Expand Down

0 comments on commit 8f3dbec

Please sign in to comment.