Skip to content

Commit

Permalink
Make doctests numpy > 1.15 compatible (related to #133)
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-wagner committed Apr 2, 2019
1 parent 67c1e20 commit 9e41a4a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 29 deletions.
3 changes: 0 additions & 3 deletions python/pygimli/__init__.py
Expand Up @@ -3,9 +3,6 @@
pyGIMLi - An open-source library for modelling and inversion in geophysics
"""

# py 2.7 compatiblity
from __future__ import division, print_function

import locale
import sys

Expand Down
16 changes: 8 additions & 8 deletions python/pygimli/meshtools/mapping.py
Expand Up @@ -59,7 +59,7 @@ def cellDataToNodeData(mesh, data, style='mean'):
>>> celldata = np.array([1, 2, 3, 4])
>>> nodedata = pg.meshtools.cellDataToNodeData(grid, celldata)
>>> print(nodedata.array())
[ 1. 1.5 2. 2. 2.5 3. 3. 3.5 4. ]
[1. 1.5 2. 2. 2.5 3. 3. 3.5 4. ]
"""
if len(data) != mesh.cellCount():
raise BaseException("Dimension mismatch, expecting cellCount(): " +
Expand Down Expand Up @@ -370,10 +370,10 @@ def interpolate(*args, **kwargs):
args: :gimliapi:`GIMLI::Mesh`, :gimliapi:`GIMLI::Mesh`, iterable
`outData = interpolate(outMesh, inMesh, vals)`
Interpolate values based on inMesh to outMesh.
Values can be of length inMesh.cellCount() interpolated to
outMesh.cellCenters() or inMesh.nodeCount() which are interpolated tp
outMesh.positions().
Values can be of length inMesh.cellCount() interpolated to
outMesh.cellCenters() or inMesh.nodeCount() which are interpolated tp
outMesh.positions().
Returns:
Interpolated values.
Expand All @@ -385,7 +385,7 @@ def interpolate(*args, **kwargs):
Arguments forwarded to :gimliapi:`GIMLI::interpolate`
kwargs:
Arguments forwarded to :gimliapi:`GIMLI::interpolate`
`interpolate(srcMesh, destMesh)`
All data from inMesh are interpolated to outMesh
Expand Down Expand Up @@ -481,7 +481,7 @@ def interpolate(*args, **kwargs):
outMat=outMat,
**kwargs)
return np.array(outMat)

if len(args) == 4: # args: (inMesh, inData, outPos, outData)

if args[1].ndim == 1 and args[2].ndim == 1 and args[3].ndim == 1:
Expand Down Expand Up @@ -515,7 +515,7 @@ def interpolate(*args, **kwargs):
y=args[3],
z=args[4],
**kwargs)

return pg.core._pygimli_.interpolate(*args, **kwargs)
# end if pg.core:

Expand Down
4 changes: 2 additions & 2 deletions python/pygimli/mplviewer/colorbar.py
Expand Up @@ -22,9 +22,9 @@ def autolevel(z, nLevs, logScale=None, zmin=None, zmax=None):
>>> from pygimli.mplviewer import autolevel
>>> x = np.linspace(1, 10, 100)
>>> autolevel(x, 3)
array([ 1., 4., 7., 10.])
array([ 1., 4., 7., 10.])
>>> autolevel(x, 3, logScale=True)
array([ 0.1, 1. , 10. , 100. ])
array([ 0.1, 1. , 10. , 100. ])
"""
locator = None
if logScale and min(z) > 0:
Expand Down
9 changes: 4 additions & 5 deletions python/pygimli/testing/__init__.py
Expand Up @@ -60,10 +60,9 @@ def test(target=None, show=False, onlydoctests=False, coverage=False,
pg.boxprint("Testing pygimli %s" % pg.__version__, sym="+")

# Numpy compatibility (array string representation has changed)
if np.__version__[:4] in ("1.14", "1.15"):
np.set_printoptions(legacy="1.13")


if np.__version__[:4] == "1.14":
pg.warn("Some doctests will fail due to old numpy version.",
"Consider upgrading to numpy >= 1.15")

if target:
if isinstance(target, str):
Expand All @@ -75,7 +74,7 @@ def test(target=None, show=False, onlydoctests=False, coverage=False,
mod_name, func_name = target.rsplit('.', 1)
mod = importlib.import_module(mod_name)
target = getattr(mod, func_name)

if show: # Keep figure openend if single function is tested
plt.ioff()

Expand Down
22 changes: 11 additions & 11 deletions python/pygimli/utils/utils.py
Expand Up @@ -176,18 +176,18 @@ def niceLogspace(vMin, vMax, nDec=10):
>>> from pygimli.utils import niceLogspace
>>> v1 = niceLogspace(vMin=0.1, vMax=0.1, nDec=1)
>>> print(v1)
[ 0.1 1. ]
[0.1 1. ]
>>> v1 = niceLogspace(vMin=0.09, vMax=0.11, nDec=1)
>>> print(v1)
[ 0.01 0.1 1. ]
[0.01 0.1 1. ]
>>> v1 = niceLogspace(vMin=0.09, vMax=0.11, nDec=10)
>>> print(len(v1))
21
>>> print(v1)
[ 0.01 0.01258925 0.01584893 0.01995262 0.02511886 0.03162278
0.03981072 0.05011872 0.06309573 0.07943282 0.1 0.12589254
0.15848932 0.19952623 0.25118864 0.31622777 0.39810717 0.50118723
0.63095734 0.79432823 1. ]
[0.01 0.01258925 0.01584893 0.01995262 0.02511886 0.03162278
0.03981072 0.05011872 0.06309573 0.07943282 0.1 0.12589254
0.15848932 0.19952623 0.25118864 0.31622777 0.39810717 0.50118723
0.63095734 0.79432823 1. ]
"""
if vMin > vMax or vMin < 1e-12:
print("vMin:", vMin, "vMax", vMax)
Expand Down Expand Up @@ -355,11 +355,11 @@ def dist(p, c=None):
>>> p[0] = [0.0, 0.0]
>>> p[1] = [0.0, 1.0]
>>> print(dist(p))
[ 0. 1. 0. 0.]
[0. 1. 0. 0.]
>>> x = pg.RVector(4, 0)
>>> y = pg.RVector(4, 1)
>>> print(dist(np.array([x, y]).T))
[ 1. 1. 1. 1.]
[1. 1. 1. 1.]
"""
if c is None:
c = pg.RVector3(0.0, 0.0, 0.0)
Expand Down Expand Up @@ -403,7 +403,7 @@ def cumDist(p):
>>> p[2] = [0.0, 1.0]
>>> p[3] = [0.0, 0.0]
>>> print(cumDist(p))
[ 0. 1. 1. 2.]
[0. 1. 1. 2.]
"""
d = np.zeros(len(p))
d[1:] = np.cumsum(dist(diff(p)))
Expand Down Expand Up @@ -631,7 +631,7 @@ def uniqueAndSum(indices, to_sum, return_index=False, verbose=False):
>>> # you need for example 3 array to find unique node positions in a mesh
>>> values = np.arange(0.1, 0.7, 0.1)
>>> print(values)
[ 0.1 0.2 0.3 0.4 0.5 0.6]
[0.1 0.2 0.3 0.4 0.5 0.6]
>>> # some values to be summed together (for example attributes of nodes)
>>> unique_idx, summed_vals = uniqueAndSum(to_sort, values)
>>> print(unique_idx)
Expand All @@ -640,7 +640,7 @@ def uniqueAndSum(indices, to_sum, return_index=False, verbose=False):
[1 2]
[2 3]]
>>> print(summed_vals)
[ 0.3 0.3 0.4 1.1]
[0.3 0.3 0.4 1.1]
"""
flag_mult = len(indices) != indices.size
if verbose:
Expand Down

0 comments on commit 9e41a4a

Please sign in to comment.