Skip to content

Commit e119195

Browse files
committed
Fixes for numpy 1.14.0 compatibility
- UPDATEIFCOPY is deprecated, replaced with similar (but not identical) WRITEBACKIFCOPY; trying to access the flag causes a deprecation warning under numpy 1.14, so just check the new flag there. - Numpy `repr` formatting of floats changed in 1.14.0 to `[1., 2., 3.]` instead of the pre-1.14 `[ 1., 2., 3.]`. Updated the tests to check for equality with the `repr(...)` value rather than the hard-coded (and now version-dependent) string representation.
1 parent 4ef1bac commit e119195

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

tests/test_eigen.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,17 +181,15 @@ def test_negative_stride_from_python(msg):
181181
double_threer(): incompatible function arguments. The following argument types are supported:
182182
1. (arg0: numpy.ndarray[float32[1, 3], flags.writeable]) -> None
183183
184-
Invoked with: array([ 5., 4., 3.], dtype=float32)
185-
""" # noqa: E501 line too long
184+
Invoked with: """ + repr(np.array([ 5., 4., 3.], dtype='float32')) # noqa: E501 line too long
186185

187186
with pytest.raises(TypeError) as excinfo:
188187
m.double_threec(second_col)
189188
assert msg(excinfo.value) == """
190189
double_threec(): incompatible function arguments. The following argument types are supported:
191190
1. (arg0: numpy.ndarray[float32[3, 1], flags.writeable]) -> None
192191
193-
Invoked with: array([ 7., 4., 1.], dtype=float32)
194-
""" # noqa: E501 line too long
192+
Invoked with: """ + repr(np.array([ 7., 4., 1.], dtype='float32')) # noqa: E501 line too long
195193

196194

197195
def test_nonunit_stride_to_python():

tests/test_numpy_array.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ def test_make_c_f_array():
137137

138138
def test_wrap():
139139
def assert_references(a, b, base=None):
140+
from distutils.version import LooseVersion
140141
if base is None:
141142
base = a
142143
assert a is not b
@@ -147,7 +148,10 @@ def assert_references(a, b, base=None):
147148
assert a.flags.f_contiguous == b.flags.f_contiguous
148149
assert a.flags.writeable == b.flags.writeable
149150
assert a.flags.aligned == b.flags.aligned
150-
assert a.flags.updateifcopy == b.flags.updateifcopy
151+
if LooseVersion(np.__version__) >= LooseVersion("1.14.0"):
152+
assert a.flags.writebackifcopy == b.flags.writebackifcopy
153+
else:
154+
assert a.flags.updateifcopy == b.flags.updateifcopy
151155
assert np.all(a == b)
152156
assert not b.flags.owndata
153157
assert b.base is base
@@ -282,17 +286,17 @@ def test_overload_resolution(msg):
282286
1. (arg0: numpy.ndarray[int32]) -> str
283287
2. (arg0: numpy.ndarray[float64]) -> str
284288
285-
Invoked with:"""
289+
Invoked with: """
286290

287291
with pytest.raises(TypeError) as excinfo:
288292
m.overloaded3(np.array([1], dtype='uintc'))
289-
assert msg(excinfo.value) == expected_exc + " array([1], dtype=uint32)"
293+
assert msg(excinfo.value) == expected_exc + repr(np.array([1], dtype='uint32'))
290294
with pytest.raises(TypeError) as excinfo:
291295
m.overloaded3(np.array([1], dtype='float32'))
292-
assert msg(excinfo.value) == expected_exc + " array([ 1.], dtype=float32)"
296+
assert msg(excinfo.value) == expected_exc + repr(np.array([1.], dtype='float32'))
293297
with pytest.raises(TypeError) as excinfo:
294298
m.overloaded3(np.array([1], dtype='complex'))
295-
assert msg(excinfo.value) == expected_exc + " array([ 1.+0.j])"
299+
assert msg(excinfo.value) == expected_exc + repr(np.array([1. + 0.j]))
296300

297301
# Exact matches:
298302
assert m.overloaded4(np.array([1], dtype='double')) == 'double'

0 commit comments

Comments
 (0)