[IPython-user] [mlabwrap-user] bug: mlab.plot([1, 2, 3], '-o') reports error
Wed Feb 28 06:13:26 CST 2007
[CC'ed to ipython-user]
> With mlabwrap-1.0b I get the following error when executing
> simple code from IPyhton prompt:
> >>> from mlabwrap import mlab
> >>> mlab.plot([1,2,1],'-o')
> ??? try, [RES0__]=exist('plot([1,2,1],'-o')');; MLABRAW_ERROR_=0; catch,
> MLABRAW_ERROR_=1; end;
> Error: Unbalanced or misused parentheses or brackets.
> array([[ 158.00158691]])
> >>> mlab.plot([1,2,1],"-o") # NO ERROR
> array([[ 158.00219727]])
> Note that for each mlab.plot command the figure is displayed correctly.
> Best regards,
This seems to be an ipython bug.
I was *really* puzzled by this. I had never seen it before and it looks weird
(I couldn't really see how this behavior could even come about), so I
downloaded mlabwrap from SF and installed from scratch and ran the example in
ipython and python and both worked fine for me.
Now there is only one place in mlabwrap.py that contains the word 'exist' and
that's in __getattr__, line 578, which is responsible for looking up matlab
function calls like ``mlab.plot`` the first time (later it's cached) -- but
it's unobvious how it would get to see something which isn't a legal attribute
name like "plot([1,2,1], '-o')". It doesn't seem to get called indirectly
either (e.g. via getattr), so I added a print call:
print "GETATTR", name
typ = self._do("exist('%s')" % name)
In python 2.4.4 I got, as expected:
> python -ic "from mlabwrap import mlab; mlab.plot([1,2,3], '-o')"
In ipython 0.6.15 (and 0.7.3, which I just downloaded) I got
In : from mlabwrap import mlab
In : mlab.plot([1,2,3], '-o')
Out: array([[ 152.00158691]])
Note that the (tentative) ipython bug is subtly different in your version of
ipython and the old one I run on the machine where I test mlabwrap; my version
of ipython apparently erroneously looks up the 'attribute' "plot([1,2,3],"
which doesn't cause an error, but your version looks up "plot([1,2,3], '-o')"
which breaks mlabwrap because it prematurely ends the matlab string literal in
the exist call.
Which version of ipython are you using? I hope it's not a too recent one
because otherwise quite a few people might see this and think mlabwrap is
badly broken and give up on it.
More information about the IPython-user