diff options
author | Allan Haldane <allan.haldane@gmail.com> | 2015-01-25 18:52:41 -0500 |
---|---|---|
committer | Allan Haldane <allan.haldane@gmail.com> | 2015-01-26 20:18:05 -0500 |
commit | 3cd9e7339c37880cff0a2f381e881e0e612c4948 (patch) | |
tree | 82c7389c16676f09fba2e239b76400817def0cbf /doc | |
parent | 937d1f25e5fee1543a55ef5e6bcf27e5a7ec3bf9 (diff) | |
download | numpy-3cd9e7339c37880cff0a2f381e881e0e612c4948.tar.gz |
BUG: Fix recarray getattr and getindex return types
This commit makes changes to `__getitem__` and `__getattr__` of recarrays:
1. recarrays no longer convert string ndarrays to chararrays, and
instead simply return ndarrays of string type.
2. attribute access and index access of fields now behaves identically
3. dtype.type is now inherited when fields of structured type are accessed
Demonstration:
>>> rec = np.rec.array([('abc ', (1,1), 1), ('abc', (2,3), 1)],
... dtype=[('foo', 'S4'), ('bar', [('A', int), ('B', int)]), ('baz', int)])
Old Behavior:
>>> type(rec.foo), type(rec['foo'])
(numpy.core.defchararray.chararray, numpy.recarray)
>>> type(rec.bar), type(rec['bar']), rec.bar.dtype.type
(numpy.recarray, numpy.recarray, numpy.void)
>>> type(rec.baz), type(rec['baz'])
(numpy.ndarray, numpy.ndarray)
New behavior:
>>> type(rec.foo), type(rec['foo'])
(numpy.ndarray, numpy.ndarray)
>>> type(rec.bar), type(rec['bar']), rec.bar.dtype.type
(numpy.recarray, numpy.recarray, numpy.record)
>>> type(rec.baz), type(rec['baz'])
(numpy.ndarray, numpy.ndarray)
Diffstat (limited to 'doc')
-rw-r--r-- | doc/release/1.10.0-notes.rst | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/doc/release/1.10.0-notes.rst b/doc/release/1.10.0-notes.rst index a04a46d17..43dc4b5c6 100644 --- a/doc/release/1.10.0-notes.rst +++ b/doc/release/1.10.0-notes.rst @@ -61,6 +61,15 @@ C API The changes to *swapaxes* also apply to the *PyArray_SwapAxes* C function, which now returns a view in all cases. +recarray field return types +~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Previously the returned types for recarray fields accessed by attribute and by +index were inconsistent, and fields of string type were returned as chararrays. +Now, fields accessed by either attribute or indexing will return an ndarray for +fields of non-structured type, and a recarray for fields of structured type. +Notably, this affect recarrays containing strings with whitespace, as trailing +whitespace is trimmed from chararrays but kept in ndarrays of string type. +Also, the dtype.type of nested structured fields is now inherited. New Features ============ |