Skip to content

Commit 9e41a4a

Browse files
Make doctests numpy > 1.15 compatible (related to #133)
1 parent 67c1e20 commit 9e41a4a

File tree

5 files changed

+25
-29
lines changed

5 files changed

+25
-29
lines changed

python/pygimli/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
pyGIMLi - An open-source library for modelling and inversion in geophysics
44
"""
55

6-
# py 2.7 compatiblity
7-
from __future__ import division, print_function
8-
96
import locale
107
import sys
118

python/pygimli/meshtools/mapping.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def cellDataToNodeData(mesh, data, style='mean'):
5959
>>> celldata = np.array([1, 2, 3, 4])
6060
>>> nodedata = pg.meshtools.cellDataToNodeData(grid, celldata)
6161
>>> print(nodedata.array())
62-
[ 1. 1.5 2. 2. 2.5 3. 3. 3.5 4. ]
62+
[1. 1.5 2. 2. 2.5 3. 3. 3.5 4. ]
6363
"""
6464
if len(data) != mesh.cellCount():
6565
raise BaseException("Dimension mismatch, expecting cellCount(): " +
@@ -370,10 +370,10 @@ def interpolate(*args, **kwargs):
370370
args: :gimliapi:`GIMLI::Mesh`, :gimliapi:`GIMLI::Mesh`, iterable
371371
`outData = interpolate(outMesh, inMesh, vals)`
372372
Interpolate values based on inMesh to outMesh.
373-
Values can be of length inMesh.cellCount() interpolated to
374-
outMesh.cellCenters() or inMesh.nodeCount() which are interpolated tp
375-
outMesh.positions().
376-
373+
Values can be of length inMesh.cellCount() interpolated to
374+
outMesh.cellCenters() or inMesh.nodeCount() which are interpolated tp
375+
outMesh.positions().
376+
377377
Returns:
378378
Interpolated values.
379379
@@ -385,7 +385,7 @@ def interpolate(*args, **kwargs):
385385
Arguments forwarded to :gimliapi:`GIMLI::interpolate`
386386
kwargs:
387387
Arguments forwarded to :gimliapi:`GIMLI::interpolate`
388-
388+
389389
`interpolate(srcMesh, destMesh)`
390390
All data from inMesh are interpolated to outMesh
391391
@@ -481,7 +481,7 @@ def interpolate(*args, **kwargs):
481481
outMat=outMat,
482482
**kwargs)
483483
return np.array(outMat)
484-
484+
485485
if len(args) == 4: # args: (inMesh, inData, outPos, outData)
486486

487487
if args[1].ndim == 1 and args[2].ndim == 1 and args[3].ndim == 1:
@@ -515,7 +515,7 @@ def interpolate(*args, **kwargs):
515515
y=args[3],
516516
z=args[4],
517517
**kwargs)
518-
518+
519519
return pg.core._pygimli_.interpolate(*args, **kwargs)
520520
# end if pg.core:
521521

python/pygimli/mplviewer/colorbar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ def autolevel(z, nLevs, logScale=None, zmin=None, zmax=None):
2222
>>> from pygimli.mplviewer import autolevel
2323
>>> x = np.linspace(1, 10, 100)
2424
>>> autolevel(x, 3)
25-
array([ 1., 4., 7., 10.])
25+
array([ 1., 4., 7., 10.])
2626
>>> autolevel(x, 3, logScale=True)
27-
array([ 0.1, 1. , 10. , 100. ])
27+
array([ 0.1, 1. , 10. , 100. ])
2828
"""
2929
locator = None
3030
if logScale and min(z) > 0:

python/pygimli/testing/__init__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,9 @@ def test(target=None, show=False, onlydoctests=False, coverage=False,
6060
pg.boxprint("Testing pygimli %s" % pg.__version__, sym="+")
6161

6262
# Numpy compatibility (array string representation has changed)
63-
if np.__version__[:4] in ("1.14", "1.15"):
64-
np.set_printoptions(legacy="1.13")
65-
66-
63+
if np.__version__[:4] == "1.14":
64+
pg.warn("Some doctests will fail due to old numpy version.",
65+
"Consider upgrading to numpy >= 1.15")
6766

6867
if target:
6968
if isinstance(target, str):
@@ -75,7 +74,7 @@ def test(target=None, show=False, onlydoctests=False, coverage=False,
7574
mod_name, func_name = target.rsplit('.', 1)
7675
mod = importlib.import_module(mod_name)
7776
target = getattr(mod, func_name)
78-
77+
7978
if show: # Keep figure openend if single function is tested
8079
plt.ioff()
8180

python/pygimli/utils/utils.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,18 @@ def niceLogspace(vMin, vMax, nDec=10):
176176
>>> from pygimli.utils import niceLogspace
177177
>>> v1 = niceLogspace(vMin=0.1, vMax=0.1, nDec=1)
178178
>>> print(v1)
179-
[ 0.1 1. ]
179+
[0.1 1. ]
180180
>>> v1 = niceLogspace(vMin=0.09, vMax=0.11, nDec=1)
181181
>>> print(v1)
182-
[ 0.01 0.1 1. ]
182+
[0.01 0.1 1. ]
183183
>>> v1 = niceLogspace(vMin=0.09, vMax=0.11, nDec=10)
184184
>>> print(len(v1))
185185
21
186186
>>> print(v1)
187-
[ 0.01 0.01258925 0.01584893 0.01995262 0.02511886 0.03162278
188-
0.03981072 0.05011872 0.06309573 0.07943282 0.1 0.12589254
189-
0.15848932 0.19952623 0.25118864 0.31622777 0.39810717 0.50118723
190-
0.63095734 0.79432823 1. ]
187+
[0.01 0.01258925 0.01584893 0.01995262 0.02511886 0.03162278
188+
0.03981072 0.05011872 0.06309573 0.07943282 0.1 0.12589254
189+
0.15848932 0.19952623 0.25118864 0.31622777 0.39810717 0.50118723
190+
0.63095734 0.79432823 1. ]
191191
"""
192192
if vMin > vMax or vMin < 1e-12:
193193
print("vMin:", vMin, "vMax", vMax)
@@ -355,11 +355,11 @@ def dist(p, c=None):
355355
>>> p[0] = [0.0, 0.0]
356356
>>> p[1] = [0.0, 1.0]
357357
>>> print(dist(p))
358-
[ 0. 1. 0. 0.]
358+
[0. 1. 0. 0.]
359359
>>> x = pg.RVector(4, 0)
360360
>>> y = pg.RVector(4, 1)
361361
>>> print(dist(np.array([x, y]).T))
362-
[ 1. 1. 1. 1.]
362+
[1. 1. 1. 1.]
363363
"""
364364
if c is None:
365365
c = pg.RVector3(0.0, 0.0, 0.0)
@@ -403,7 +403,7 @@ def cumDist(p):
403403
>>> p[2] = [0.0, 1.0]
404404
>>> p[3] = [0.0, 0.0]
405405
>>> print(cumDist(p))
406-
[ 0. 1. 1. 2.]
406+
[0. 1. 1. 2.]
407407
"""
408408
d = np.zeros(len(p))
409409
d[1:] = np.cumsum(dist(diff(p)))
@@ -631,7 +631,7 @@ def uniqueAndSum(indices, to_sum, return_index=False, verbose=False):
631631
>>> # you need for example 3 array to find unique node positions in a mesh
632632
>>> values = np.arange(0.1, 0.7, 0.1)
633633
>>> print(values)
634-
[ 0.1 0.2 0.3 0.4 0.5 0.6]
634+
[0.1 0.2 0.3 0.4 0.5 0.6]
635635
>>> # some values to be summed together (for example attributes of nodes)
636636
>>> unique_idx, summed_vals = uniqueAndSum(to_sort, values)
637637
>>> print(unique_idx)
@@ -640,7 +640,7 @@ def uniqueAndSum(indices, to_sum, return_index=False, verbose=False):
640640
[1 2]
641641
[2 3]]
642642
>>> print(summed_vals)
643-
[ 0.3 0.3 0.4 1.1]
643+
[0.3 0.3 0.4 1.1]
644644
"""
645645
flag_mult = len(indices) != indices.size
646646
if verbose:

0 commit comments

Comments
 (0)