[Scipy-tickets] [SciPy] #1230: scipy.io.matlab.loadmat does not squeeze
SciPy Trac
scipy-tickets@scipy....
Mon Jul 12 13:30:33 CDT 2010
#1230: scipy.io.matlab.loadmat does not squeeze
----------------------+-----------------------------------------------------
Reporter: tpikonen | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone: 0.8.0
Component: scipy.io | Version: devel
Keywords: mat-file |
----------------------+-----------------------------------------------------
loadmat, even when called with squeeze_me=1 returns scalars as 0-d arrays,
which is very annoying. Also chars_as_strings does not do what is
expected. Example with the git head of scipy:
octave:1> a = struct("f1", 0.5, "f2", "A String")
a =
{
f1 = 0.50000
f2 = A String
}
octave:2> save -mat testcase.mat a
Python 2.6.5+ (release26-maint, Jul 6 2010, 12:58:20)
[GCC 4.4.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy.io.matlab as mio
>>> adict = mio.loadmat('testcase.mat', struct_as_record=0, squeeze_me=1,
chars_as_strings=1)
>>> asq = adict['a']
>>> asq.f1
array(0.5)
>>> asq.f2
array(u'A String',
dtype='<U8')
>>> scipy.__version__
'0.9.0.dev'
>>> numpy.__version__
'1.4.1'
What should be (IMHO) returned with these input arguments to loadmat are
asq.f1 == 0.5 and asq.f2 == 'A String'.
Investigation into io.matlab code shows that the dtype conversion, which
uses the type table obtained from miobase.convert_dtypes always results in
values with dtype.isbuiltin == 0, even for basic types such as floats.
This in turn breaks mio_utils.squeeze_element.
Patching convert_dtypes to not change the byteorder with newbyteorder
makes scalar values read out ok, but probably breaks something else.
--
Ticket URL: <http://projects.scipy.org/scipy/ticket/1230>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.
More information about the Scipy-tickets
mailing list