Skip to content

Commit 2cfb95e

Browse files
committed
TST: adapt nipy doctests to numpy 1.14
Numpy 1.14 has new printing output. Use a version of Chris M's nibabel fix to revert printing output to 1.13 style.
1 parent 30be196 commit 2cfb95e

File tree

16 files changed

+73
-15
lines changed

16 files changed

+73
-15
lines changed

nipy/algorithms/registration/affine.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
from ...externals.transforms3d.quaternions import mat2quat, quat2axangle
1010
from .transform import Transform
1111

12+
# Legacy repr printing from numpy.
13+
from nipy.testing import legacy_printing as setup_module # noqa
14+
1215
# Globals
1316
RADIUS = 100
1417
MAX_ANGLE = 1e10 * 2 * np.pi

nipy/algorithms/slicetiming/timefuncs.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030

3131
import numpy as np
3232

33+
# Legacy repr printing from numpy.
34+
from nipy.testing import legacy_printing as setup_module # noqa
35+
3336
# Dictionary (key, value) == (name, function) for slice timing functions
3437
SLICETIME_FUNCTIONS = {}
3538

nipy/algorithms/statistics/formula/formulae.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@
128128

129129
from nipy.algorithms.utils.matrices import matrix_rank, full_rank
130130

131+
# Legacy repr printing from numpy.
132+
from nipy.testing import legacy_printing as setup_module # noqa
133+
134+
131135
@np.deprecate(message = "Please use sympy.Dummy instead of this function")
132136
def make_dummy(name):
133137
""" Make dummy variable of given name

nipy/algorithms/statistics/models/regression.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636

3737
from .model import LikelihoodModel, LikelihoodModelResults
3838

39+
# Legacy repr printing from numpy.
40+
from nipy.testing import legacy_printing as setup_module # noqa
41+
3942

4043
class OLSModel(LikelihoodModel):
4144
""" A simple ordinary least squares model.
@@ -342,9 +345,9 @@ class ARModel(OLSModel):
342345
AR coefficients: [-0.7220361 -1.05365352]
343346
AR coefficients: [-0.72229201 -1.05408193]
344347
AR coefficients: [-0.722278 -1.05405838]
345-
>>> results.theta #doctest: +FP_6DP
348+
>>> results.theta #doctest: +NP_ALLCLOSE
346349
array([ 1.59564228, -0.58562172])
347-
>>> results.t() #doctest: +FP_6DP
350+
>>> results.t() #doctest: +NP_ALLCLOSE
348351
array([ 38.0890515 , -3.45429252])
349352
>>> print(results.Tcontrast([0,1])) #doctest: +FP_6DP
350353
<T contrast: effect=-0.58562172384377043, sd=0.16953449108110835,

nipy/algorithms/statistics/models/utils.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
from __future__ import print_function
55
from __future__ import absolute_import
66

7+
__docformat__ = 'restructuredtext'
8+
79
import numpy as np
810
import scipy.interpolate
911

10-
__docformat__ = 'restructuredtext'
11-
1212

1313
def mad(a, c=0.6745, axis=0):
1414
"""
@@ -24,22 +24,24 @@ def mad(a, c=0.6745, axis=0):
2424

2525

2626
class StepFunction(object):
27-
"""
28-
A basic step function: values at the ends are handled in the simplest
29-
way possible: everything to the left of x[0] is set to ival; everything
30-
to the right of x[-1] is set to y[-1].
27+
""" A basic step function
28+
29+
Values at the ends are handled in the simplest way possible: everything to
30+
the left of ``x[0]`` is set to `ival`; everything to the right of ``x[-1]``
31+
is set to ``y[-1]``.
3132
3233
Examples
3334
--------
3435
>>> x = np.arange(20)
3536
>>> y = np.arange(20)
3637
>>> f = StepFunction(x, y)
3738
>>>
38-
>>> print(f(3.2))
39+
>>> f(3.2)
3940
3.0
40-
>>> print(f([[3.2,4.5],[24,-3.1]]))
41-
[[ 3. 4.]
42-
[ 19. 0.]]
41+
>>> res = f([[3.2, 4.5],[24, -3.1]])
42+
>>> np.all(res == [[ 3, 4],
43+
... [19, 0]])
44+
True
4345
"""
4446

4547
def __init__(self, x, y, ival=0., sorted=False):

nipy/algorithms/statistics/rft.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@
1717
from __future__ import absolute_import
1818

1919
import numpy as np
20-
from numpy.linalg import pinv
20+
from numpy.linalg import pinv
2121

2222
from scipy import stats
2323
from scipy.misc import factorial
2424
from scipy.special import gamma, gammaln, beta, hermitenorm
2525

26+
# Legacy repr printing from numpy.
27+
from nipy.testing import legacy_printing as setup_module # noqa
28+
29+
2630
def binomial(n, k):
2731
""" Binomial coefficient
2832

nipy/core/image/image.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
input_axis_index)
2828
from ..reference.array_coords import ArrayCoordMap
2929

30+
# Legacy repr printing from numpy.
31+
from nipy.testing import legacy_printing as setup_module # noqa
32+
3033

3134
class Image(object):
3235
""" The `Image` class provides the core object type used in nipy.

nipy/core/image/image_spaces.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@
8080
from ..reference import spaces as rsp
8181
from ..reference.coordinate_map import AffineTransform
8282

83+
# Legacy repr printing from numpy.
84+
from nipy.testing import legacy_printing as setup_module # noqa
85+
8386

8487
def xyz_affine(img, name2xyz=None):
8588
""" Return xyz affine from image `img` if possible, or raise error

nipy/core/reference/array_coords.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
from .coordinate_map import shifted_range_origin
2525
from .coordinate_system import CoordinateSystem
2626

27+
# Legacy repr printing from numpy.
28+
from nipy.testing import legacy_printing as setup_module # noqa
29+
2730

2831
class ArrayCoordMap(object):
2932
""" Class combining coordinate map and array shape
@@ -187,6 +190,7 @@ def __repr__(self):
187190
return "ArrayCoordMap(\n coordmap=" + \
188191
'\n '.join(repr(self.coordmap).split('\n')) + ',\n shape=%s' % repr(self.shape) + '\n)'
189192

193+
190194
def _slice(coordmap, shape, *slices):
191195
"""
192196
Slice a 'voxel' CoordinateMap's function_domain with slices. A
@@ -264,7 +268,6 @@ def _slice(coordmap, shape, *slices):
264268
A = A.astype(function_domain.coord_dtype)
265269
slice_cmap = AffineTransform(function_domain, coordmap.function_domain, A)
266270
return ArrayCoordMap(compose(coordmap, slice_cmap), tuple(newshape))
267-
268271

269272

270273
class Grid(object):

nipy/core/reference/coordinate_map.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
product as coordsys_product
7777
)
7878

79+
# Legacy repr printing from numpy.
80+
from nipy.testing import legacy_printing as setup_module # noqa
81+
7982
# shorthand
8083
CS = CoordinateSystem
8184

0 commit comments

Comments
 (0)