record array: passing formats as tuple raises error (Trac #1139)

Open
#1,737 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
data

Research direction

Start in numpy/core/records.py at format_parser._parseFormats, using the traceback as the entry point. Reproduce rec.fromarrays with a tuple and with a list passed to formats; done means the tuple form is accepted consistently with the list form.

Written by the indexing model from the issue text.

Description

00 - Bug component: numpy._core

Original ticket http://projects.scipy.org/numpy/ticket/1139 on 2009-06-17 by @huard, assigned to unknown.

If a tuple is passed to the formats argument to rec.fromarrays for example, the following error is raised:

/usr/local/lib/python2.5/site-packages/numpy-1.4.0.dev7045-py2.5-linux-x86_64.egg/numpy/core/records.pyc in fromarrays(arrayList, dtype, shape, formats, names, titles, aligned, byteorder)
    506         _names = descr.names
    507     else:
--> 508         parsed = format_parser(formats, names, titles, aligned, byteorder)
    509         _names = parsed._names
    510         descr = parsed._descr

/usr/local/lib/python2.5/site-packages/numpy-1.4.0.dev7045-py2.5-linux-x86_64.egg/numpy/core/records.pyc in __init__(self, formats, names, titles, aligned, byteorder)
    110     """
    111     def __init__(self, formats, names, titles, aligned=False, byteorder=None):
--> 112         self._parseFormats(formats, aligned)
    113         self._setfieldnames(names, titles)
    114         self._createdescr(byteorder)

/usr/local/lib/python2.5/site-packages/numpy-1.4.0.dev7045-py2.5-linux-x86_64.egg/numpy/core/records.pyc in _parseFormats(self, formats, aligned)
    124                 formats.append('')
    125             formats = ','.join(formats)
--> 126         dtype = sb.dtype(formats, aligned)
    127         fields = dtype.fields
    128         if fields is None:

TypeError: data type not understood
WARNING: Failure executing file: <load.py>

If the tuple is converted into a list, then everything works fine.

Dominant language
Python
Stars
32.8k
Forks
12.8k
Avg merge
1d 7h
Merged PRs (30d)
197

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from numpy/numpy

All issues in numpy/numpy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.