[Numpy-discussion] numarray vs IPython

Fernando Perez Fernando.Perez at colorado.edu
Tue Dec 7 11:06:02 EST 2004


Andrea Riciputi schrieb:
> The same here (OS X, Python 2.3.4, ipython 0.6.5). The problem is due 
> to the way in which numarray performs its tests. It relies on the 
> Python module doctest that execute the script in doc strings. I think 
> that since in numarray doc strings the expected output is written in 
> the standard Python way (i.e. >>> foo) while ipython writes out 
> something like "Out[n]: foo" the checks fail.

Thanks for that info, this is most likely the culprit.  Here's a simple test 
to confirm things: start ipython as 'ipython --classic', which disables the 
fancy prompt system and makes it produce regular python prompts.  Run the 
tests there and see what happens.

Since numarray is more and more likely to be run by ipython users, it might be 
worth adding a bit of robustness to these tests when under ipython.  Here are 
some suggestions, starting with the simplest:

1. Run a first 'empty' test just to do prompt detection.  If this one fails, do:

try:
   __IPYTHON__
except NameError:
   print 'Big time problem, not caused by ipython'
else:
   print 'Run ipython --classic for doctests to work'

or some fancier version of the above.

2. Even better, patch doctest to recognize prompts based on a regexp.  The 
python-mode.el guys did this for (x)emacs support, and it now works very well 
with ipython.  The python-mode CVS code can be studied for the proper regexps. 
  By default this regexp can be set to recognize the normal ipython prompts.

3. If you do 2, and you want to get real fancy, the numarray doctest could 
build the regexp automatically, from the ipython prompt configuration strings. 
  These are always available at runtime:

In [1]: __IPYTHON__.rc.prom
__IPYTHON__.rc.prompt_in1  __IPYTHON__.rc.prompt_in2  __IPYTHON__.rc.prompt_out

In [1]: __IPYTHON__.rc.prompt_in1
Out[1]: 'In [\\#]:'

In [2]: __IPYTHON__.rc.prompt_in2
Out[2]: '   .\\D.:'

In [3]: __IPYTHON__.rc.prompt_out
Out[3]: 'Out[\\#]:'


So the situation looks not too bad.  There's a quick fix (--classic) for now, 
and if someone feels up to the task of patching doctest, a pretty elegant 
solution can be implemented.

Regards,

f




More information about the NumPy-Discussion mailing list