[Numpy-discussion] Problems casting object arrays to string type on Ubuntu

Michael Droettboom mdroe@stsci....
Tue Nov 24 09:58:29 CST 2009


Sorry I missed your message the first time around.

I suspect you're running into this bug:

http://projects.scipy.org/numpy/ticket/1235

This has been fixed in SVN r7514, (and thus 1.4 pre releases), so it's 
not a platform difference.

The workaround (at the expense of performance, of course) is to cast to 
a list then cast to a string array.  I'm not sure if there's a better 
(i.e. more performant) workaround.  But you could (in your client code) 
check for the version of Numpy and act accordingly.

Mike

Dan Yamins wrote:
> Really, no idea about this?   (Sorry if my original email was unclear.)
>
> On Sat, Nov 21, 2009 at 3:27 PM, Dan Yamins <dyamins@gmail.com 
> <mailto:dyamins@gmail.com>> wrote:
>
>     Hi all,
>
>     I'm having some issues casting object arrays to string type,
>     especially on my Ubuntu installation. (Ubuntu Jaunty, 9.04, with
>     Numpy v. 1.3.)
>
>     With small arrays, the conversion is just wrong.  With large
>     arrays, there seems to be some memory corruption.   Conversion to
>     int or float (when appropriate) seems to work.
>
>     For instance, here are some examples of errors with small arrays:
>
>       >>> X = numpy.array([13,14],'object')
>       >>> X.astype('|S2')
>       array(['13', '\xb2'],
>           dtype='|S2')
>       >>> X.astype('int')      #conversion to int or float seems to
>     work fine
>       array([13, 14])
>       >>> X.astype(float)
>       array([ 13.,  14.])
>       >>> X = numpy.array(['cat','bat'],'object')
>       >>> X.astype('|S3')
>       array(['cat', '\x00ba'],
>            dtype='|S3')
>
>     Large arrays:
>
>        In [24]: X = numpy.array(['cat','bat']*300000,'object')
>        In [25]: Y = X.astype('|S3')
>        *** glibc detected *** /usr/bin/python: munmap_chunk(): invalid
>     pointer: 0xb7cd5008 ***
>
>
>     I do NOT have this problem with Numpy 1.4.0.dev7746, installed on
>     my OSX 10.5.8 machine.   There, everything seems to work fine.
>
>     What's going on?  I feel like I've seem some traffic about related
>     issues on the list before, but I couldn't quite tell from reading
>     the threads what the "final upshot" of the discussion was ...   
>     Is this something that was fixed in recent NumPy 1.4 releases, or
>     is something about my Ubuntu vs. OSX installations?    Generally
>     speaking can I / should I be relying on casting from object arrays
>     to do the "right" (or "intuitive") thing?
>
>     thanks,
>     Dan
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>   

-- 
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA



More information about the NumPy-Discussion mailing list