[Scipy-svn] r6426 - in trunk/scipy/io/matlab: . tests
scipy-svn at scipy.org
scipy-svn at scipy.org
Sat May 29 17:48:08 EDT 2010
Author: matthew.brett at gmail.com
Date: 2010-05-29 16:48:08 -0500 (Sat, 29 May 2010)
New Revision: 6426
Modified:
trunk/scipy/io/matlab/mio4.py
trunk/scipy/io/matlab/mio5.py
trunk/scipy/io/matlab/miobase.py
trunk/scipy/io/matlab/tests/test_mio.py
Log:
RF - move to struct_as_record default of True
Modified: trunk/scipy/io/matlab/mio4.py
===================================================================
--- trunk/scipy/io/matlab/mio4.py 2010-05-29 21:48:01 UTC (rev 6425)
+++ trunk/scipy/io/matlab/mio4.py 2010-05-29 21:48:08 UTC (rev 6426)
@@ -332,7 +332,7 @@
dims = matdims(arr, oned_as)
if len(dims) > 2:
warnings.warn('Matlab 4 files only support <=2 '
- 'dimensions; future versions of scipy will '
+ 'dimensions; the next version of scipy will '
'raise an error when trying to write >2D arrays '
'to matlab 4 format files',
DeprecationWarning,
Modified: trunk/scipy/io/matlab/mio5.py
===================================================================
--- trunk/scipy/io/matlab/mio5.py 2010-05-29 21:48:01 UTC (rev 6425)
+++ trunk/scipy/io/matlab/mio5.py 2010-05-29 21:48:08 UTC (rev 6426)
@@ -252,7 +252,7 @@
squeeze_me=False,
chars_as_strings=True,
matlab_compatible=False,
- struct_as_record=None, # default False, for now
+ struct_as_record=True,
uint16_codec=None
):
'''Initializer for matlab 5 file format reader
@@ -264,12 +264,6 @@
Set codec to use for uint16 char arrays (e.g. 'utf-8').
Use system default codec if None
'''
- # Deal with deprecations
- if struct_as_record is None:
- warnings.warn("Using struct_as_record default value (False)" +
- " This will change to True in future versions",
- FutureWarning, stacklevel=2)
- struct_as_record = False
super(MatFile5Reader, self).__init__(
mat_stream,
byte_order,
Modified: trunk/scipy/io/matlab/miobase.py
===================================================================
--- trunk/scipy/io/matlab/miobase.py 2010-05-29 21:48:01 UTC (rev 6425)
+++ trunk/scipy/io/matlab/miobase.py 2010-05-29 21:48:08 UTC (rev 6426)
@@ -39,16 +39,12 @@
squeeze_me=False, chars_as_strings=False, mat_dtype=True,
struct_as_record=True)''',
'struct_arg':
- '''struct_as_record : {False, True} optional
+ '''struct_as_record : {True, False} optional
Whether to load matlab structs as numpy record arrays, or as
old-style numpy arrays with dtype=object. Setting this flag to
- False replicates the behaviour of scipy version 0.6 (returning
- numpy object arrays). The preferred setting is True, because it
- allows easier round-trip load and save of matlab files. In a
- future version of scipy, we will change the default setting to
- True, and following versions may remove this flag entirely. For
- now, we set the default to False, for backwards compatibility, but
- issue a warning.''',
+ False replicates the behaviour of scipy version 0.7.x (returning
+ numpy object arrays). The default setting is True, because it
+ allows easier round-trip load and save of matlab files.''',
'matstream_arg':
'''mat_stream : file-like
object with file API, open for reading''',
@@ -324,7 +320,7 @@
squeeze_me=False,
chars_as_strings=True,
matlab_compatible=False,
- struct_as_record=None
+ struct_as_record=True
):
'''
Initializer for mat file reader
Modified: trunk/scipy/io/matlab/tests/test_mio.py
===================================================================
--- trunk/scipy/io/matlab/tests/test_mio.py 2010-05-29 21:48:01 UTC (rev 6425)
+++ trunk/scipy/io/matlab/tests/test_mio.py 2010-05-29 21:48:08 UTC (rev 6426)
@@ -34,7 +34,6 @@
MatFile5Reader, MatlabFunction
# Use future defaults to silence unwanted test warnings
-loadmat_future = partial(loadmat, struct_as_record=True)
savemat_future = partial(savemat, oned_as='row')
class MatFile5Reader_future(MatFile5Reader):
def __init__(self, *args, **kwargs):
@@ -276,7 +275,7 @@
def _load_check_case(name, files, case):
for file_name in files:
- matdict = loadmat_future(file_name, struct_as_record=True)
+ matdict = loadmat(file_name, struct_as_record=True)
label = "test %s; file %s" % (name, file_name)
for k, expected in case.items():
k_label = "%s, variable %s" % (label, k)
@@ -331,7 +330,7 @@
mat_stream.close()
mat_stream = gzip.open( fname,mode='rb')
- actual = loadmat_future(mat_stream, struct_as_record=True)
+ actual = loadmat(mat_stream, struct_as_record=True)
mat_stream.close()
finally:
shutil.rmtree(tmpdir)
@@ -347,7 +346,7 @@
assert_true(len(filenames)>0)
for filename in filenames:
assert_raises(NotImplementedError,
- loadmat_future,
+ loadmat,
filename,
struct_as_record=True)
@@ -359,9 +358,7 @@
mres = loadmat(fname, struct_as_record=True)
# This neither
mres = loadmat(fname, struct_as_record=False)
- # This should
- yield assert_raises, FutureWarning, loadmat, fname
- # This too
+ # This should - because of deprecated system path search
yield assert_raises, DeprecationWarning, find_mat_file, fname
warnings.resetwarnings()
@@ -476,7 +473,7 @@
stream = StringIO()
savemat_future(stream, {'dict':d})
stream.seek(0)
- vals = loadmat_future(stream)
+ vals = loadmat(stream)
def test_1d_shape():
@@ -486,12 +483,12 @@
# silence warnings for tests
warnings.simplefilter('ignore')
savemat(stream, {'oned':arr}, format='5')
- vals = loadmat_future(stream)
+ vals = loadmat(stream)
yield assert_equal, vals['oned'].shape, (5,1)
# Current 4 behavior is 1D -> row vector
stream = StringIO()
savemat(stream, {'oned':arr}, format='4')
- vals = loadmat_future(stream)
+ vals = loadmat(stream)
yield assert_equal, vals['oned'].shape, (1, 5)
for format in ('4', '5'):
# can be explicitly 'column' for oned_as
@@ -499,14 +496,14 @@
savemat(stream, {'oned':arr},
format=format,
oned_as='column')
- vals = loadmat_future(stream)
+ vals = loadmat(stream)
yield assert_equal, vals['oned'].shape, (5,1)
# but different from 'row'
stream = StringIO()
savemat(stream, {'oned':arr},
format=format,
oned_as='row')
- vals = loadmat_future(stream)
+ vals = loadmat(stream)
yield assert_equal, vals['oned'].shape, (1,5)
warnings.resetwarnings()
@@ -517,12 +514,12 @@
stream = StringIO()
savemat_future(stream, {'arr':arr})
raw_len = len(stream.getvalue())
- vals = loadmat_future(stream)
+ vals = loadmat(stream)
yield assert_array_equal, vals['arr'], arr
stream = StringIO()
savemat_future(stream, {'arr':arr}, do_compression=True)
compressed_len = len(stream.getvalue())
- vals = loadmat_future(stream)
+ vals = loadmat(stream)
yield assert_array_equal, vals['arr'], arr
yield assert_true, raw_len>compressed_len
# Concatenate, test later
@@ -530,11 +527,11 @@
arr2[0,0] = 1
stream = StringIO()
savemat_future(stream, {'arr':arr, 'arr2':arr2}, do_compression=False)
- vals = loadmat_future(stream)
+ vals = loadmat(stream)
yield assert_array_equal, vals['arr2'], arr2
stream = StringIO()
savemat_future(stream, {'arr':arr, 'arr2':arr2}, do_compression=True)
- vals = loadmat_future(stream)
+ vals = loadmat(stream)
yield assert_array_equal, vals['arr2'], arr2
@@ -556,9 +553,9 @@
#
filename = pjoin(test_data_path,'test_skip_variable.mat')
#
- # Prove that it loads with loadmat_future
+ # Prove that it loads with loadmat
#
- d = loadmat_future(filename, struct_as_record=True)
+ d = loadmat(filename, struct_as_record=True)
yield assert_true, d.has_key('first')
yield assert_true, d.has_key('second')
#
@@ -577,7 +574,7 @@
filename = pjoin(test_data_path,'test_empty_struct.mat')
# before ticket fix, this would crash with ValueError, empty data
# type
- d = loadmat_future(filename, struct_as_record=True)
+ d = loadmat(filename, struct_as_record=True)
a = d['a']
yield assert_equal, a.shape, (1,1)
yield assert_equal, a.dtype, np.dtype(np.object)
@@ -586,7 +583,7 @@
arr = np.array((), dtype='U')
# before ticket fix, this used to give data type not understood
savemat_future(stream, {'arr':arr})
- d = loadmat_future(stream)
+ d = loadmat(stream)
a2 = d['arr']
yield assert_array_equal, a2, arr
@@ -602,11 +599,11 @@
arr[1]['f2'] = 'not perl'
stream = StringIO()
savemat_future(stream, {'arr': arr})
- d = loadmat_future(stream, struct_as_record=False)
+ d = loadmat(stream, struct_as_record=False)
a20 = d['arr'][0,0]
yield assert_equal, a20.f1, 0.5
yield assert_equal, a20.f2, 'python'
- d = loadmat_future(stream, struct_as_record=True)
+ d = loadmat(stream, struct_as_record=True)
a20 = d['arr'][0,0]
yield assert_equal, a20['f1'], 0.5
yield assert_equal, a20['f2'], 'python'
@@ -625,11 +622,11 @@
c.field2 = 'a string'
stream = StringIO()
savemat_future(stream, {'c': c})
- d = loadmat_future(stream, struct_as_record=False)
+ d = loadmat(stream, struct_as_record=False)
c2 = d['c'][0,0]
yield assert_equal, c2.field1, 1
yield assert_equal, c2.field2, 'a string'
- d = loadmat_future(stream, struct_as_record=True)
+ d = loadmat(stream, struct_as_record=True)
c2 = d['c'][0,0]
yield assert_equal, c2['field1'], 1
yield assert_equal, c2['field2'], 'a string'
@@ -704,7 +701,7 @@
warnings.simplefilter('ignore')
savemat_future(stream, {'a': arr}, format='4')
warnings.resetwarnings()
- d = loadmat_future(stream)
+ d = loadmat(stream)
yield assert_array_equal, d['a'], arr.reshape((6,4))
@@ -734,7 +731,7 @@
st = {'sparsefield': SP.coo_matrix(np.eye(4))}
stream = StringIO()
savemat_future(stream, {'a':st})
- d = loadmat_future(stream, struct_as_record=True)
+ d = loadmat(stream, struct_as_record=True)
yield assert_array_equal, d['a'][0,0]['sparsefield'].todense(), np.eye(4)
@@ -743,9 +740,9 @@
in_d = {'st':{'one':1, 'two':2}}
savemat_future(stream, in_d)
# no error without squeeze
- out_d = loadmat_future(stream, struct_as_record=False)
+ out_d = loadmat(stream, struct_as_record=False)
# previous error was with squeeze, with mat_struct
- out_d = loadmat_future(stream,
+ out_d = loadmat(stream,
struct_as_record=False,
squeeze_me=True,
)
@@ -757,7 +754,7 @@
in_arr = np.array(['Hello', 'Foob'])
out_arr = np.array(['Hello', 'Foob '])
savemat_future(stream, dict(a=in_arr))
- res = loadmat_future(stream)
+ res = loadmat(stream)
# resulted in [u'HloolFoa', u'elWrdobr']
yield assert_array_equal, res['a'], out_arr
stream.truncate(0)
@@ -774,6 +771,6 @@
in_arr_u = in_arr.astype('U')
out_arr_u = out_arr.astype('U')
savemat_future(stream, {'a': in_arr_u})
- res = loadmat_future(stream)
+ res = loadmat(stream)
yield assert_array_equal, res['a'], out_arr_u
More information about the Scipy-svn
mailing list