@@ -105,7 +105,8 @@ def _get_fieldspec(dtype):
105
105
106
106
def get_names (adtype ):
107
107
"""
108
- Returns the field names of the input datatype as a tuple.
108
+ Returns the field names of the input datatype as a tuple. Input datatype
109
+ has to have fields otherwise error is raised.
109
110
110
111
Parameters
111
112
----------
@@ -115,15 +116,10 @@ def get_names(adtype):
115
116
Examples
116
117
--------
117
118
>>> from numpy.lib import recfunctions as rfn
118
- >>> rfn.get_names(np.empty((1,), dtype=int))
119
- Traceback (most recent call last):
120
- ...
121
- AttributeError: 'numpy.ndarray' object has no attribute 'names'
122
-
123
- >>> rfn.get_names(np.empty((1,), dtype=[('A',int), ('B', float)]))
124
- Traceback (most recent call last):
125
- ...
126
- AttributeError: 'numpy.ndarray' object has no attribute 'names'
119
+ >>> rfn.get_names(np.empty((1,), dtype=[('A', int)]).dtype)
120
+ ('A',)
121
+ >>> rfn.get_names(np.empty((1,), dtype=[('A',int), ('B', float)]).dtype)
122
+ ('A', 'B')
127
123
>>> adtype = np.dtype([('a', int), ('b', [('ba', int), ('bb', int)])])
128
124
>>> rfn.get_names(adtype)
129
125
('a', ('b', ('ba', 'bb')))
@@ -141,8 +137,9 @@ def get_names(adtype):
141
137
142
138
def get_names_flat (adtype ):
143
139
"""
144
- Returns the field names of the input datatype as a tuple. Nested structure
145
- are flattened beforehand.
140
+ Returns the field names of the input datatype as a tuple. Input datatype
141
+ has to have fields otherwise error is raised.
142
+ Nested structure are flattened beforehand.
146
143
147
144
Parameters
148
145
----------
@@ -152,14 +149,10 @@ def get_names_flat(adtype):
152
149
Examples
153
150
--------
154
151
>>> from numpy.lib import recfunctions as rfn
155
- >>> rfn.get_names_flat(np.empty((1,), dtype=int)) is None
156
- Traceback (most recent call last):
157
- ...
158
- AttributeError: 'numpy.ndarray' object has no attribute 'names'
159
- >>> rfn.get_names_flat(np.empty((1,), dtype=[('A',int), ('B', float)]))
160
- Traceback (most recent call last):
161
- ...
162
- AttributeError: 'numpy.ndarray' object has no attribute 'names'
152
+ >>> rfn.get_names_flat(np.empty((1,), dtype=[('A', int)]).dtype) is None
153
+ False
154
+ >>> rfn.get_names_flat(np.empty((1,), dtype=[('A',int), ('B', str)]).dtype)
155
+ ('A', 'B')
163
156
>>> adtype = np.dtype([('a', int), ('b', [('ba', int), ('bb', int)])])
164
157
>>> rfn.get_names_flat(adtype)
165
158
('a', 'b', 'ba', 'bb')
0 commit comments