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

nipy/core/reference/spaces.py

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

1414
from ...externals.six import string_types
1515

16+
# Legacy repr printing from numpy.
17+
from nipy.testing import legacy_printing as setup_module # noqa
18+
19+
1620
class XYZSpace(object):
1721
""" Class contains logic for spaces with XYZ coordinate systems
1822

nipy/core/reference/tests/test_coordinate_map.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
from numpy.testing import (assert_array_equal, assert_almost_equal, dec)
2626

27+
# Legacy repr printing from numpy.
28+
from nipy.testing import legacy_printing
2729

2830
# Dtypes for testing coordinate map creation / processing
2931
_SYMPY_SAFE_DTYPES = (np.sctypes['int'] + np.sctypes['uint'] +
@@ -61,6 +63,7 @@ def g(x):
6163
[ 8, 9, 10, 11],
6264
[ 8, 9, 10, 11],
6365
[ 0, 0, 0, 1]]))
66+
legacy_printing()
6467

6568

6669
def test_shift_origin():

nipy/core/utils/generators.py

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

2424
from nipy.utils import seq_prod
2525

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

2730
def parcels(data, labels=None, exclude=()):
2831
""" Return a generator for ``[data == label for label in labels]``

nipy/externals/transforms3d/quaternions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818
from __future__ import absolute_import
1919

2020
import math
21+
2122
import numpy as np
2223

24+
# Legacy repr printing from numpy.
25+
from nipy.testing import legacy_printing as setup_module # noqa
26+
2327
_MAX_FLOAT = np.maximum_sctype(np.float)
2428
_FLOAT_EPS = np.finfo(np.float).eps
2529

nipy/modalities/fmri/utils.py

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

3232
from nipy.algorithms.statistics.formula.formulae import Term, Formula
3333

34+
# Legacy repr printing from numpy.
35+
from nipy.testing import legacy_printing as setup_module # noqa
36+
3437
T = Term('t')
3538

3639

nipy/testing/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
import os
2828

29-
#__all__ = ['funcfile', 'anatfile']
29+
import numpy as np
3030

3131
# Discover directory path
3232
filepath = os.path.abspath(__file__)
@@ -48,3 +48,13 @@
4848
from nose.tools import assert_true, assert_false
4949
except ImportError:
5050
pass
51+
52+
53+
def legacy_printing():
54+
""" Set numpy print options to "legacy" for new versions of numpy
55+
56+
If imported into a file, nosetest will run this before any doctests.
57+
"""
58+
from distutils.version import LooseVersion
59+
if LooseVersion(np.__version__) >= LooseVersion('1.14'):
60+
np.set_printoptions(legacy="1.13")

0 commit comments

Comments
 (0)