10000 1.9.1 Backports by juliantaylor · Pull Request #5255 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

1.9.1 Backports #5255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 2, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix issue with fromarrays not correctly determining a format string f…
…or unicode data (in the process eliminate some unnecessary cruft)
    8000
  • Loading branch information
embray authored and juliantaylor committed Nov 2, 2014
commit 27c87972dc850ea8d25ebf5daba74cba658c581a
10 changes: 3 additions & 7 deletions numpy/core/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
# are equally allowed

numfmt = nt.typeDict
_typestr = nt._typestr

def find_duplicate(list):
"""Find duplication in a list, return a list of duplicated elements"""
Expand Down Expand Up @@ -527,15 +526,12 @@ def fromarrays(arrayList, dtype=None, shape=None, formats=None,
if formats is None and dtype is None:
# go through each object in the list to see if it is an ndarray
# and determine the formats.
formats = ''
formats = []
for obj in arrayList:
if not isinstance(obj, ndarray):
raise ValueError("item in the array list must be an ndarray.")
formats += _typestr[obj.dtype.type]
if issubclass(obj.dtype.type, nt.flexible):
formats += repr(obj.itemsize)
formats += ','
formats = formats[:-1]
formats.append(obj.dtype.str)
formats = ','.join(formats)

if dtype is not None:
descr = sb.dtype(dtype)
Expand Down
9 changes: 9 additions & 0 deletions numpy/core/tests/test_records.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import division, absolute_import, print_function

import sys
from os import path
import numpy as np
from numpy.testing import *
Expand All @@ -15,6 +16,14 @@ def test_fromrecords(self):
r = np.rec.fromrecords([[456, 'dbe', 1.2], [2, 'de', 1.3]],
names='col1,col2,col3')
assert_equal(r[0].item(), (456, 'dbe', 1.2))
assert_equal(r['col1'].dtype.kind, 'i')
if sys.version_info[0] >= 3:
assert_equal(r['col2'].dtype.kind, 'U')
assert_equal(r['col2'].dtype.itemsize, 12)
else:
assert_equal(r['col2'].dtype.kind, 'S')
assert_equal(r['col2'].dtype.itemsize, 3)
assert_equal(r['col3'].dtype.kind, 'f')

def test_method_array(self):
r = np.rec.array(asbytes('abcdefg') * 100, formats='i2,a3,i4', shape=3, byteorder='big')
Expand Down
0