[Scipy-tickets] [SciPy] #1095: scipy.io.savemat does not work on dictionaries

SciPy Trac scipy-tickets@scipy....
Wed Jan 20 21:22:46 CST 2010

#1095: scipy.io.savemat does not work on dictionaries
 Reporter:  juli    |       Owner:  somebody
     Type:  defect  |      Status:  new     
 Priority:  normal  |   Milestone:  0.8.0   
Component:  Other   |     Version:  0.7.0   
 Keywords:          |  
 I tried the example from the documentation to save a python dictionary as
 a .mat file. It raised an exception and looking at the code a bit it
 didn't seem like a bug. Does this feature not exist anymore? If so it
 would be a bummer, as I find it quite useful.

 Here is what I did:

 In [1]: import scipy

 In [2]: import numpy

 In [3]: numpy.__version__

 Out[3]: '1.3.0'

 In [4]: scipy.__version__

 Out[4]: '0.7.0'

 In [5]: import scipy.io as sio

 In [6]: a_dict = {'field1': 0.5, 'field2': 'a string'}

 In [7]: sio.savemat('saved_struct.mat', {'a_dict': a_dict})
 TypeError                                 Traceback (most recent call

 /usr/local/src/deb_pkg/build_python_num/<ipython console> in <module>()

 /usr/lib/python2.5/site-packages/scipy/io/matlab/mio.py in
 savemat(file_name, mdict, appendmat, format, long_field_names)
     157     else:
     158         raise ValueError("Format should be '4' or '5'")
 --> 159     MW.put_variables(mdict)
     160     if file_is_string:
     161         file_stream.close()

 /usr/lib/python2.5/site-packages/scipy/io/matlab/mio5.py in
 put_variables(self, mdict)
     971                 var,
     972                 name,
 --> 973                 is_global)
     974             mat_writer.write()
     975             stream = self.writer_getter.stream

 /usr/lib/python2.5/site-packages/scipy/io/matlab/mio5.py in
 matrix_writer_factory(self, arr, name, is_global)
     893             # No interesting conversion possible
     894             raise TypeError('Could not convert %s (type %s) to
 --> 895                             % (arr, type(arr)))
     896         args = (self.stream,
     897                 narr,

 TypeError: Could not convert {'field2': 'a string', 'field1': 0.5} (type
 <type 'dict'>) to array

Ticket URL: <http://projects.scipy.org/scipy/ticket/1095>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.

More information about the Scipy-tickets mailing list