Skip to content

Commit 569fc6a

Browse files
committed
Fix docstring and examples for rfn.get_names*
1 parent 2ada30d commit 569fc6a

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

numpy/lib/recfunctions.py

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ def _get_fieldspec(dtype):
105105

106106
def 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+
has to 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

142138
def 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+
has to 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

Comments
 (0)