Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

BUG: fix test failure in Matlab/mio_utils.

The cause seems to be a subtle change in the Cython <--> Numpy interaction from
1.5.1 to master.

Also remove yield statements from tests, they're not necessary.
  • Loading branch information...
commit 754f69cb4d79645d17d6e04d51b67472cf945d88 1 parent e90c736
@rgommers rgommers authored
View
2,513 scipy/io/matlab/mio_utils.c
1,508 additions, 1,005 deletions not shown
View
8 scipy/io/matlab/mio_utils.pyx
@@ -21,10 +21,10 @@ cpdef object squeeze_element(cnp.ndarray arr):
``arr.item`` to return a ``mat_struct`` object from a struct array '''
if not arr.size:
return np.array([])
- arr = np.squeeze(arr)
- if not arr.shape and arr.dtype.isbuiltin: # 0d coverted to scalar
- return arr.item()
- return arr
+ arr2 = np.squeeze(arr)
+ if (not arr2.shape) and arr2.dtype.isbuiltin: # 0d coverted to scalar
+ return arr2.item()
+ return arr2
cpdef cnp.ndarray chars_to_strings(in_arr):
View
32 scipy/io/matlab/tests/test_mio_utils.py
@@ -4,34 +4,29 @@
import numpy as np
-from nose.tools import assert_true, assert_false, \
- assert_equal, assert_raises
-
from numpy.testing import assert_array_equal, assert_array_almost_equal, \
- run_module_suite
+ run_module_suite, assert_
from scipy.io.matlab.mio_utils import cproduct, squeeze_element, \
chars_to_strings
def test_cproduct():
- yield assert_equal, cproduct(()), 1
- yield assert_equal, cproduct((1,)), 1
- yield assert_equal, cproduct((1,3)), 3
- yield assert_equal, cproduct([1,3]), 3
+ assert_(cproduct(()) == 1)
+ assert_(cproduct((1,)) == 1)
+ assert_(cproduct((1,3)) == 3)
+ assert_(cproduct([1,3]) == 3)
def test_squeeze_element():
a = np.zeros((1,3))
- yield (assert_array_equal,
- np.squeeze(a),
- squeeze_element(a))
+ assert_array_equal(np.squeeze(a), squeeze_element(a))
# 0d output from squeeze gives scalar
sq_int = squeeze_element(np.zeros((1,1), dtype=np.float))
- yield assert_true, isinstance(sq_int, float)
+ assert_(isinstance(sq_int, float))
# Unless it's a structured array
sq_sa = squeeze_element(np.zeros((1,1),dtype=[('f1', 'f')]))
- yield assert_true, isinstance(sq_sa, np.ndarray)
+ assert_(isinstance(sq_sa, np.ndarray))
def test_chars_strings():
@@ -40,20 +35,21 @@ def test_chars_strings():
str_arr = np.array(strings, dtype='U6') # shape (4,)
chars = [list(s) for s in strings]
char_arr = np.array(chars, dtype='U1') # shape (4,6)
- yield assert_array_equal, chars_to_strings(char_arr), str_arr
+ assert_array_equal(chars_to_strings(char_arr), str_arr)
ca2d = char_arr.reshape((2,2,6))
sa2d = str_arr.reshape((2,2))
- yield assert_array_equal, chars_to_strings(ca2d), sa2d
+ assert_array_equal(chars_to_strings(ca2d), sa2d)
ca3d = char_arr.reshape((1,2,2,6))
sa3d = str_arr.reshape((1,2,2))
- yield assert_array_equal, chars_to_strings(ca3d), sa3d
+ assert_array_equal(chars_to_strings(ca3d), sa3d)
# Fortran ordered arrays
char_arrf = np.array(chars, dtype='U1', order='F') # shape (4,6)
- yield assert_array_equal, chars_to_strings(char_arrf), str_arr
+ assert_array_equal(chars_to_strings(char_arrf), str_arr)
# empty array
arr = np.array([['']], dtype='U1')
out_arr = np.array([''], dtype='U1')
- yield assert_array_equal, chars_to_strings(arr), out_arr
+ assert_array_equal(chars_to_strings(arr), out_arr)
+
if __name__ == "__main__":
run_module_suite()
Please sign in to comment.
Something went wrong with that request. Please try again.