matplotlib and scipy/numarray arrays: annoying crashes...

Hi,
I have installed python2.4, the last versions of scipy and numarray, and matplotlib 0.85.
I have now constant problems trying to use my scripts, where I often make use of arrays.
It often gives me things like:

···

==========
/usr/lib/python2.4/site-packages/numarray/numarraycore.py:376: UserWarning: __array__ returned non-NumArray instance
  _warnings.warn("__array__ returned non-NumArray instance")
---------------------------------------------------------------------------
numarray.libnumarray.error Traceback (most recent call last)
...
error: Type object lookup returned NULL for type -1

or similar problems which seems linked to the fact that somehow my arrays have :

<type 'scipy.ndarray'>

So if I try to do for example:
   plot(x,y)

where x and y seem to be scipy.ndarray, it crashes with errors such as the one mentioned above.
(I tried to cast them as numarray.asarray but it keeps its scipy.ndarray whatever I do...)

So my question is :

- does anybody know what really changed in the last versions of scipy/numarray/matplotlib which now induces these crashes (before all was fine) ?

- what should I do to solve it (maybe I have to systematically use numarray functions by specifying "numarray." in front of all the "zeros", "arange" and so on..., but I have the impression this may not solve everything) ?

- how do I transform a scipy.ndarray into something compatible for matplotlib?

thanks for the help (I realize this is maybe more a numarray/scipy question, but maybe someone from the matplotlib crowd can help me: it seems that most of my scripts are crashing in similar ways - probably bad writing on my side... but I am here to learn..)

Eric

== for info, I use:
matplotlib version 0.85
platform is linux2
numerix numarray 1.4.1
backend GTKAgg version 2.8.0
Python 2.4.1 (#1, Sep 13 2005, 00:39:20)
IPython 0.6.15 -- An enhanced Interactive Python.

--

Observatoire de Lyon emsellem@...419...
9 av. Charles-Andre tel: +33 4 78 86 83 84
69561 Saint-Genis Laval Cedex fax: +33 4 78 86 83 86
France http://www-obs.univ-lyon1.fr/eric.emsellem

Hi Eric,

···

On Tue, 29 Nov 2005, Eric Emsellem wrote:

Hi,
I have installed python2.4, the last versions of scipy and numarray, and
matplotlib 0.85.
I have now constant problems trying to use my scripts, where I often
make use of arrays.
It often gives me things like:

==========
/usr/lib/python2.4/site-packages/numarray/numarraycore.py:376:
UserWarning: __array__ returned non-NumArray instance
  _warnings.warn("__array__ returned non-NumArray instance")
---------------------------------------------------------------------------
numarray.libnumarray.error Traceback
(most recent call last)
...
error: Type object lookup returned NULL for type -1

or similar problems which seems linked to the fact that somehow my
arrays have :

<type 'scipy.ndarray'>

So if I try to do for example:
   plot(x,y)

where x and y seem to be scipy.ndarray, it crashes with errors such as
the one mentioned above.
(I tried to cast them as numarray.asarray but it keeps its scipy.ndarray
whatever I do...)

Do you have simple example which reproducibly gives the above error?
(Just to be sure: are you using the new scipy, or the old one?)

Best, Arnd

Eric Emsellem wrote:

Hi,
I have installed python2.4, the last versions of scipy and numarray, and matplotlib 0.85.
I have now constant problems trying to use my scripts, where I often make use of arrays.
It often gives me things like:

==========
/usr/lib/python2.4/site-packages/numarray/numarraycore.py:376: UserWarning: __array__ returned non-NumArray instance
_warnings.warn("__array__ returned non-NumArray instance")
---------------------------------------------------------------------------
numarray.libnumarray.error Traceback (most recent call last)
...
error: Type object lookup returned NULL for type -1

I think this should be posted as a bug to the numarray users group. I'm not sure exactly what the problem is, but somehow numarray is using the __array__ method of scipy arrays (which return an ndarray not a numarray) instead of the __array_struct__ method to get the actual information out of the array.

The new array protocol should make interoperability of the arrays seamless, but there still may be issues with implementation. The ugly step-mother of the array protocol was the __array__ method. The problem, is that each array implementation expects that method to produce an object of its own type so it gets in the way of interoperability. I suspect numarray is trying to access the __array__ method to get the type the array should be (rather than using the array protocol first).

where x and y seem to be scipy.ndarray, it crashes with errors such as the one mentioned above.
(I tried to cast them as numarray.asarray but it keeps its scipy.ndarray whatever I do...)

I don't see why numarray.asarray() would not return numarray objects unless it is more forgiving of what constitutes an array than I would be.

So my question is :

- does anybody know what really changed in the last versions of scipy/numarray/matplotlib which now induces these crashes (before all was fine) ?

The problem is that lots of people know part of what is going on. Users encountering bugs are the glue to seam up the rest. Things are going to get a lot better, so have patience during the transition period.

- what should I do to solve it (maybe I have to systematically use numarray functions by specifying "numarray." in front of all the "zeros", "arange" and so on..., but I have the impression this may not solve everything) ?

- how do I transform a scipy.ndarray into something compatible for matplotlib?

My impression is that matplotlib should work with just scipy (no need for numarray). I would try that route. It may be that your matplotlib installation is confused about which array package to use. I'm not sure.

However, numarray should hear about the conversion problems which could probably be fixed with an easy patch.

-Travis O.