@@ -105,7 +105,8 @@ def _get_fieldspec(dtype):
105105
106106def get_names (adtype ):
107107 """
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+ must have fields otherwise error is raised.
109110
110111 Parameters
111112 ----------
@@ -115,15 +116,10 @@ def get_names(adtype):
115116 Examples
116117 --------
117118 >>> 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')
127123 >>> adtype = np.dtype([('a', int), ('b', [('ba', int), ('bb', int)])])
128124 >>> rfn.get_names(adtype)
129125 ('a', ('b', ('ba', 'bb')))
@@ -141,8 +137,9 @@ def get_names(adtype):
141137
142138def get_names_flat (adtype ):
143139 """
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+ must have fields otherwise error is raised.
142+ Nested structure are flattened beforehand.
146143
147144 Parameters
148145 ----------
@@ -152,14 +149,10 @@ def get_names_flat(adtype):
152149 Examples
153150 --------
154151 >>> 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')
163156 >>> adtype = np.dtype([('a', int), ('b', [('ba', int), ('bb', int)])])
164157 >>> rfn.get_names_flat(adtype)
165158 ('a', 'b', 'ba', 'bb')
0 commit comments