diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-08-11 02:12:22 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-08-11 02:12:22 +0000 |
commit | cceb25c8c4b0d7c35d2629c9a8004abb8fda9574 (patch) | |
tree | e646487e746015c2645c7927c6398474d34bb0d2 | |
parent | b963f883d4db71676ee9be260f63f38f6aead8e6 (diff) | |
download | numpy-cceb25c8c4b0d7c35d2629c9a8004abb8fda9574.tar.gz |
Fix record class so that it returns chararrays and record arrays as needed as well.
-rw-r--r-- | numpy/core/records.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/numpy/core/records.py b/numpy/core/records.py index 9f6ba82a0..cf8e94425 100644 --- a/numpy/core/records.py +++ b/numpy/core/records.py @@ -122,8 +122,16 @@ class record(nt.void): pass fielddict = nt.void.__getattribute__(self, 'dtype').fields res = fielddict.get(attr,None) - if res: - return self.getfield(*res[:2]) + if res: + obj = self.getfield(*res[:2]) + # if it has fields return a recarray, + # if it's a string return 'SU' return a chararray + # otherwise return a normal array + if obj.dtype.fields: + return obj.view(recarray) + if obj.dtype.char in 'SU': + return obj.view(chararray) + return obj else: raise AttributeError, "'record' object has no "\ "attribute '%s'" % attr |