[Numpy-discussion] Problem with concatenate and object arrays

Travis Oliphant oliphant.travis at ieee.org
Mon Sep 4 18:34:08 EDT 2006


Fernando Perez wrote:
> Hi all,
>
> I'm wondering if the following difference in behavior of object arrays should 
> be considered a bug.  Let a and b be:
>
> In [21]: a = [0,1]
>
> In [22]: b = [ None, None]
>
> If we concatenate a with an empty list, it works:
>
> In [23]: numpy.concatenate(([],a))
> Out[23]: array([0, 1])
>
> But not so for b:
>
> In [24]: numpy.concatenate(([],b))
> ---------------------------------------------------------------------------
> exceptions.ValueError                                Traceback (most recent 
> call last)
>
> /home/fperez/<ipython console>
>
> ValueError: 0-d arrays can't be concatenated
>   

This is a result of PyArray_FromAny changing when object arrays are 
explicitly requested (which they are in this case --- although behind 
the scenes). 

I decided to revert to the previous behavior and only use the 
Object_FromNestedLists code when an error occurs and the user explicitly 
requested an object array.  

The downside is that you can not place empty lists (or tuples) as 
objects in an object-array construct.  as you could before.   Given the 
trouble people had with the "feature,"  it seems wise to use it only 
when previous code would have raised an error.

-Travis





More information about the NumPy-Discussion mailing list