[SciPy-dev] Bug or inconsistent behaviour

Jörgen Stenarson jorgen.stenarson at bostream.nu
Sat Dec 3 08:05:45 CST 2005


Hi,
I stumbled on inconsistent behaviour, perhaps its a bug, in the array 
creation function. When calling array with a list of integers and a 
character I get very different result in scipy, numarray and numeric.

numarray throws TypeError exceptions no matter where the character is in 
the list.

Numeric throws an exception if the character is the first element of the 
list (because it tries to call len on the other integers), but if it is 
anywhere else in the list it gets silently converted to an integer using 
ord if it is a single character but there is a "TypeError: integer 
required" if it is a string.

Scipy always converts such a lists to a stringtype array with the 
integer being converted to a string using str, the size of the 
stringtype depends on which order the elements are in the list.

I'm not sure which behaviour is supposed to be "right". I prefer 
numarray's as it is most predictable and will throw an error if there is 
a mix of string and numeric data in a list I try to convert to an array.

best regards,
Jörgen Stenarson

 >>> import numarray
 >>> numarray.__version__
'1.4.1'
 >>> numarray.array([1,2,3])
array([1, 2, 3])
 >>> numarray.array([1,2,3,"a"])
.
.
.
TypeError: Expecting a python numeric type, got something else.
 >>> numarray.array(["a",1,2,3])
.
.
.
TypeError: Expecting a python numeric type, got something else.
 >>> numarray.array([1,"ac",2,3])
.
.
.
TypeError: Expecting a python numeric type, got something else.

 >>> import Numeric
 >>> Numeric.__version__
'24.2'
 >>> Numeric.array([1,2,3,"a"])
array([ 1,  2,  3, 97])
 >>> Numeric.array([1,2,3,"va"])
.
.
.
TypeError: an integer is required

 >>> Numeric.array(["a",1,2,3])
.
.
.
TypeError: len() of unsized object

 >>> import scipy
 >>> scipy.__core_version__
'0.7.0.1495'
 >>> scipy.array([1,2,3,"a"])
array([1, 2, 3, a], dtype=string4)
 >>> scipy.array(["a",1,2,3])
array([a, 1, 2, 3], dtype=string1)




More information about the Scipy-dev mailing list