Skip to content

Bug in rec.fromarrays in handling length-0 strings (Trac #1303), now with segfault. #1901

Closed

Description

@thouis

Original ticket http://projects.scipy.org/numpy/ticket/1303 on 2009-11-25 by trac user dyamins, assigned to unknown.

I'm using 1.4.0.dev7746, on Mac OSX 10.5.8. The problems below occur both for python 2.5 compiled 32-bit as well as python2.6 compiled 64-bit.

A problem arises when you try to create a record array passing a type of '|S0'.

>>> Cols = [ [ 'test' ]*10 , [ '' ]*10]

When not passing any dtype, this is created into a recarray with no problem:

>>> np.rec.fromarrays(Cols)
rec.array([('test', _), ('test', _), ('test', _), ('test', _),
       ('test', _), ('test', _), ('test', _), ('test', _),
       ('test', _), ('test', _)],
      dtype=[('f0', '|S4'), ('f1', '|S1')])

However, trouble arises when I try to pass a length-0 dtype explicitly.

>>> d = np.dtype([('A', '|S4'), ('B', '|S')])
>>> np.rec.fromarrays(Cols,dtype=d)
rec.array([('test', _), ('\x00est', _), ('\x00est', _), ('\x00est', _),
       ('\x00est', _), ('\x00est', _), ('\x00est', _), ('\x00est', _),
       ('\x00est', _), ('\x00est', _)],
      dtype=[('A', '|S4'), ('B', '|S0')])

The same thing occurs if I cast to np arrays before passing to np.rec.fromarrays:

>>> _arrays = [np.array(Cols[0],'|S4'),np.array(Cols[1],'|S')]
[array(['test', 'test', 'test', 'test', 'test', 'test', 'test', 'test',
       'test', 'test'],
      dtype='|S4'),
 array([_, _, _, _, _, _, _, _, _, _],
      dtype='|S1')]

>>> np.rec.fromarrays(_arrays,dtype=d)
rec.array([('test', _), ('\x00est', _), ('\x00est', _), ('\x00est', _),
       ('\x00est', _), ('\x00est', _), ('\x00est', _), ('\x00est', _),
       ('\x00est', _), ('\x00est', _)],
      dtype=[('A', '|S4'), ('B', '|S0')])

Activity

  1. thouis commented on Oct 19, 2012

    @thouis
    ContributorAuthor

    Milestone changed to Unscheduled by @mwiebe on 2011-03-25

  2. charris commented on Feb 21, 2014

    @charris
    Member

    In 1.9-devel it segfaults. May be related to #2585.

  3. ahaldane commented on Jun 2, 2016

    @ahaldane
    Member

    Fixed by #6430

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions