Skip to content

dtype field names cannot be unicode (Trac #1814) #2407

@numpy-gitbot

Description

@numpy-gitbot

Original ticket http://projects.scipy.org/numpy/ticket/1814 on 2011-04-29 by @jonovik, assigned to unknown.

Is there a reason why Unicode strings are not accepted as field names for record arrays?

>>> np.dtype([("a", int)])
dtype([('a', '<i4')])
>>> np.dtype([(u"a", int)])
TypeError: data type not understood

A workaround is .encode("ascii").

>>> np.dtype([(u"a".encode("ascii"), int)])
dtype([('a', '<i4')])

It is okay for the type specification to be Unicode.

>>> np.dtype([("a", u"S2")])
dtype([('a', '|S2')])}}}

I came across this while building a record array from data in a Microsoft Excel spreadsheet using pythoncom and win32com. Converting to ascii isn't too much of a hassle, but maybe it wouldn't be difficult to allow Unicode strings as field names?

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