diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-07-19 15:24:47 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-07-19 15:24:47 +0000 |
commit | 5172ae3f46a2da8935e643c7ee6a2086fca3956c (patch) | |
tree | 2ec874eaea07cca772965d8a72a24d7b61cc1c30 /numpy/core/records.py | |
parent | b884d998f468f89704dae39ef4d1e0b2bc71a9f3 (diff) | |
download | numpy-5172ae3f46a2da8935e643c7ee6a2086fca3956c.tar.gz |
Fix up rec.array when dtype and formats are both None for cases that support it. Alter dtype=object parsing so that tuples and lists are recognized as sequences.
Diffstat (limited to 'numpy/core/records.py')
-rw-r--r-- | numpy/core/records.py | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/numpy/core/records.py b/numpy/core/records.py index 44f8df8e3..554788253 100644 --- a/numpy/core/records.py +++ b/numpy/core/records.py @@ -460,35 +460,44 @@ def array(obj, dtype=None, shape=None, offset=0, strides=None, formats=None, raise ValueError("Must define formats (or dtype) if object is "\ "None, string, or an open file") + kwds = {} if dtype is not None: dtype = sb.dtype(dtype) - else: + elif formats is not None: dtype = format_parser(formats, names, titles, aligned, byteorder)._descr + else: + kwds = {'formats': formats, + 'names' : names, + 'titles' : titles, + 'aligned' : aligned, + 'byteorder' : byteorder + } if obj is None: if shape is None: raise ValueError("Must define a shape if obj is None") return recarray(shape, dtype, buf=obj, offset=offset, strides=strides) elif isinstance(obj, str): - return fromstring(obj, dtype, shape=shape, offset=offset) + return fromstring(obj, dtype, shape=shape, offset=offset, **kwds) elif isinstance(obj, (list, tuple)): if isinstance(obj[0], sb.ndarray): - return fromarrays(obj, dtype=dtype, shape=shape) + return fromarrays(obj, dtype=dtype, shape=shape, **kwds) else: - return fromrecords(obj, dtype=dtype, shape=shape) + return fromrecords(obj, dtype=dtype, shape=shape, **kwds) elif isinstance(obj, recarray): new = obj.copy() - new.dtype = dtype + if dtype is not None: + new.dtype = dtype return new elif isinstance(obj, file): return fromfile(obj, dtype=dtype, shape=shape, offset=offset) elif isinstance(obj, sb.ndarray): - if (obj.dtype != dtype): + if dtype is not None and (obj.dtype != dtype): obj.dtype = dtype res = obj.view(recarray) if issubclass(res.dtype.type, nt.void): |