summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2022-05-22 10:33:47 +0300
committerGitHub <noreply@github.com>2022-05-22 10:33:47 +0300
commiteece996beacc8d78bb48749fe515986ede95bf9e (patch)
treef5daf6fa6447c6b4aee11327116b655385588eb5
parentc549d844a478cc7e4e16b5674fcdedba73bde958 (diff)
parent2932e9110c889703e8edf16e4167f1acc0cb99cb (diff)
downloadnumpy-eece996beacc8d78bb48749fe515986ede95bf9e.tar.gz
Merge pull request #21566 from bsipocz/docstring_fix_get_names_flat
DOC: Fix docstring and examples for rfn.get_names*
-rw-r--r--numpy/lib/recfunctions.py33
1 files changed, 13 insertions, 20 deletions
diff --git a/numpy/lib/recfunctions.py b/numpy/lib/recfunctions.py
index ee4fbcd74..4a27c3286 100644
--- a/numpy/lib/recfunctions.py
+++ b/numpy/lib/recfunctions.py
@@ -105,7 +105,8 @@ def _get_fieldspec(dtype):
def get_names(adtype):
"""
- Returns the field names of the input datatype as a tuple.
+ Returns the field names of the input datatype as a tuple. Input datatype
+ must have fields otherwise error is raised.
Parameters
----------
@@ -115,15 +116,10 @@ def get_names(adtype):
Examples
--------
>>> from numpy.lib import recfunctions as rfn
- >>> rfn.get_names(np.empty((1,), dtype=int))
- Traceback (most recent call last):
- ...
- AttributeError: 'numpy.ndarray' object has no attribute 'names'
-
- >>> rfn.get_names(np.empty((1,), dtype=[('A',int), ('B', float)]))
- Traceback (most recent call last):
- ...
- AttributeError: 'numpy.ndarray' object has no attribute 'names'
+ >>> rfn.get_names(np.empty((1,), dtype=[('A', int)]).dtype)
+ ('A',)
+ >>> rfn.get_names(np.empty((1,), dtype=[('A',int), ('B', float)]).dtype)
+ ('A', 'B')
>>> adtype = np.dtype([('a', int), ('b', [('ba', int), ('bb', int)])])
>>> rfn.get_names(adtype)
('a', ('b', ('ba', 'bb')))
@@ -141,8 +137,9 @@ def get_names(adtype):
def get_names_flat(adtype):
"""
- Returns the field names of the input datatype as a tuple. Nested structure
- are flattened beforehand.
+ Returns the field names of the input datatype as a tuple. Input datatype
+ must have fields otherwise error is raised.
+ Nested structure are flattened beforehand.
Parameters
----------
@@ -152,14 +149,10 @@ def get_names_flat(adtype):
Examples
--------
>>> from numpy.lib import recfunctions as rfn
- >>> rfn.get_names_flat(np.empty((1,), dtype=int)) is None
- Traceback (most recent call last):
- ...
- AttributeError: 'numpy.ndarray' object has no attribute 'names'
- >>> rfn.get_names_flat(np.empty((1,), dtype=[('A',int), ('B', float)]))
- Traceback (most recent call last):
- ...
- AttributeError: 'numpy.ndarray' object has no attribute 'names'
+ >>> rfn.get_names_flat(np.empty((1,), dtype=[('A', int)]).dtype) is None
+ False
+ >>> rfn.get_names_flat(np.empty((1,), dtype=[('A',int), ('B', str)]).dtype)
+ ('A', 'B')
>>> adtype = np.dtype([('a', int), ('b', [('ba', int), ('bb', int)])])
>>> rfn.get_names_flat(adtype)
('a', 'b', 'ba', 'bb')