From 75591fcd3ec18d775642767fc5eb68aebac404c4 Mon Sep 17 00:00:00 2001 From: Per A Brodtkorb Date: Thu, 1 Nov 2018 21:15:30 +0100 Subject: [PATCH] Made doctests more robust. --- wafo/containers.py | 9 +++++---- wafo/dctpack.py | 8 ++++---- wafo/gaussian.py | 4 ++-- wafo/integrate.py | 4 ++-- wafo/misc.py | 28 +++++++++++++++------------- wafo/spectrum/core.py | 4 ++-- 6 files changed, 30 insertions(+), 27 deletions(-) diff --git a/wafo/containers.py b/wafo/containers.py index 188fda5..a59fae8 100644 --- a/wafo/containers.py +++ b/wafo/containers.py @@ -187,8 +187,9 @@ class PlotData(object): >>> y = np.sin(x) >>> ci = PlotData(np.vstack((y*.9, y*1.1)).T, x) >>> d = PlotData(y, x, children=[ci]) - >>> d.integrate(0, np.pi/2, return_ci=True) - array([ 0.99940055, 0.89946049, 1.0993406 ]) + >>> np.allclose(d.integrate(0, np.pi/2, return_ci=True), + ... [ 0.99940055, 0.89946049, 1.0993406 ]) + True >>> np.allclose(d.integrate(0, 5, return_ci=True), ... d.integrate(return_ci=True)) True @@ -209,7 +210,7 @@ class PlotData(object): return res def _plot_children(self, axis, plotflag, kwds): - axis.hold('on') + # axis.hold('on') tmp = [] child_args = kwds.pop('plot_args_children', tuple(self.plot_args_children)) @@ -413,7 +414,7 @@ def plot1d(axis, args, data, dataCI, plotflag, *varargin, **kwds): plotfun = getattr(axis, fun) h.extend(plotfun(args, data, *varargin, **kwds)) if np.any(dataCI) and plottype < 3: - axis.hold(True) + # axis.hold(True) h.extend(plotfun(args, dataCI, 'r--')) elif plottype == 4: h = axis.errorbar(args, data, diff --git a/wafo/dctpack.py b/wafo/dctpack.py index ef4c498..9762e49 100644 --- a/wafo/dctpack.py +++ b/wafo/dctpack.py @@ -95,10 +95,10 @@ def dct(x, type=2, n=None, axis=-1, norm='ortho'): # @ReservedAssignment -------- >>> import numpy as np >>> x = np.arange(5) - >>> np.abs(x-idct(dct(x)))<1e-14 - array([ True, True, True, True, True], dtype=bool) - >>> np.abs(x-dct(idct(x)))<1e-14 - array([ True, True, True, True, True], dtype=bool) + >>> np.allclose(x, idct(dct(x))) + True + >>> np.allclose(x, dct(idct(x))) + True References ---------- diff --git a/wafo/gaussian.py b/wafo/gaussian.py index c9582ce..d2cc947 100644 --- a/wafo/gaussian.py +++ b/wafo/gaussian.py @@ -705,8 +705,8 @@ def prbnormnd(correl, a, b, abseps=1e-4, releps=1e-3, maxpts=None, method=0): ... [0.0019456719705212067, 1.0059406844578488e-05, 0]) True - >>> np.abs(val-Et)< err0+terr0 - array([ True], dtype=bool) + >>> np.allclose(np.abs(val-Et) < err0+terr0, True) + True >>> 'val = %2.5f' % val 'val = 0.00195' diff --git a/wafo/integrate.py b/wafo/integrate.py index e9796fb..779fbcf 100644 --- a/wafo/integrate.py +++ b/wafo/integrate.py @@ -453,8 +453,8 @@ def la_roots(n, alpha=0, method='newton'): ------- >>> import numpy as np >>> [x,w] = h_roots(10) - >>> np.sum(x*w) - 1.3352627380516791e-17 + >>> np.allclose(np.sum(x*w) < 1e-16, True) + True See also -------- diff --git a/wafo/misc.py b/wafo/misc.py index c8b888a..9e09b0f 100644 --- a/wafo/misc.py +++ b/wafo/misc.py @@ -273,18 +273,18 @@ def lazyselect(condlist, choicelist, arrays, default=0): Examples -------- >>> x = np.arange(6) - >>> np.select([x <3, x > 3], [x**2, x**3], default=0) - array([ 0, 1, 4, 0, 64, 125]) - - >>> lazyselect([x < 3, x > 3], [lambda x: x**2, lambda x: x**3], (x,)) - array([ 0., 1., 4., 0., 64., 125.]) - + >>> np.allclose(np.select([x <3, x > 3], [x**2, x**3], default=0), + ... [ 0, 1, 4, 0, 64, 125]) + True + >>> np.allclose(lazyselect([x < 3, x > 3], [lambda x: x**2, lambda x: x**3], (x,)), + ... [ 0., 1., 4., 0., 64., 125.]) + True >>> a = -np.ones_like(x) - >>> lazyselect([x < 3, x > 3], - ... [lambda x, a: x**2, lambda x, a: a * x**3], - ... (x, a)) - array([ 0., 1., 4., 0., -64., -125.]) - + >>> np.allclose(lazyselect([x < 3, x > 3], + ... [lambda x, a: x**2, lambda x, a: a * x**3], + ... (x, a)), + ... [ 0., 1., 4., 0., -64., -125.]) + True """ arrays = np.broadcast_arrays(*arrays) tcode = np.mintypecode([a.dtype.char for a in arrays]) @@ -1185,6 +1185,8 @@ def findrfc(tp, h=0.0, method='clib'): ind, ix = clib.findrfc(y, h) ix = int(ix) else: + if isinstance(method, str): + method = 2 ind = numba_misc.findrfc(y, h, method) ix = len(ind) @@ -1909,8 +1911,8 @@ def betaloge(z, w): Example ------- >>> import wafo.misc as wm - >>> np.abs(wm.betaloge(3,2)+2.48490665)<1e-7 - array([ True], dtype=bool) + >>> np.allclose(wm.betaloge(3,2), -2.48490665) + True See also -------- diff --git a/wafo/spectrum/core.py b/wafo/spectrum/core.py index 402f819..1d95db4 100644 --- a/wafo/spectrum/core.py +++ b/wafo/spectrum/core.py @@ -1248,8 +1248,8 @@ class SpecData1D(PlotData): if paramt is None: # (2.5 * mean distance between extremes) - distanceBetweenExtremes = 5 * pi * sqrt(m[1] / m[2]) - paramt = [0, distanceBetweenExtremes, 43] + distance_between_extremes = 5 * pi * sqrt(m[1] / m[2]) + paramt = [0, distance_between_extremes, 43] if paramu is None: paramu = [-5 * sqrt(m[0]), 5 * sqrt(m[0]), 41]