summaryrefslogtreecommitdiff
path: root/numpy/lib/recfunctions.py
diff options
context:
space:
mode:
authorBrigitta Sipőcz <bsipocz@gmail.com>2022-05-21 19:44:33 -0700
committerBrigitta Sipőcz <bsipocz@gmail.com>2022-05-21 19:50:18 -0700
commit569fc6a40ea53054409e00c7d1c0e7f5f53cb0ce (patch)
treee5d7a09f63c9cedb1d48f4fb96ce5c8cd2154838 /numpy/lib/recfunctions.py
parent2ada30dd4883649f7a9dd24ccfed750c2095c52e (diff)
downloadnumpy-569fc6a40ea53054409e00c7d1c0e7f5f53cb0ce.tar.gz
Fix docstring and examples for rfn.get_names*
Diffstat (limited to 'numpy/lib/recfunctions.py')
-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..ba9f9dd32 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
+ has to 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
+ has to 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')