[Numpy-discussion] chararray stripping trailing whitespace a bug?

Christopher Hanley chanley at stsci.edu
Mon May 10 11:40:45 EDT 2010


On Mon, May 10, 2010 at 11:23 AM, Neil Crighton <neilcrighton at gmail.com> wrote:
> I've been working with pyfits, which uses numpy chararrays. I've discovered the
> hard way that chararrays silently remove trailing whitespace:
>
>>>> a = np.array(['a '])
>>>> b = a.view(np.chararray)
>>>> a[0]
> 'a '
>>>> b[0]
> 'a'
>
> Note the string values stored in memory are unchanged. This behaviour caused a
> bug in a program I've been writing, and seems like a bad idea in general. Is it
> intentional?
>
> Neil

This is an intentional "feature", not a bug.

Chris



-- 
Christopher Hanley
Senior Systems Software Engineer
Space Telescope Science Institute
3700 San Martin Drive
Baltimore MD, 21218
(410) 338-4338



More information about the NumPy-Discussion mailing list