From 569fc6a40ea53054409e00c7d1c0e7f5f53cb0ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brigitta=20Sip=C5=91cz?= Date: Sat, 21 May 2022 19:44:33 -0700 Subject: Fix docstring and examples for rfn.get_names* --- numpy/lib/recfunctions.py | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) (limited to 'numpy/lib/recfunctions.py') 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') -- cgit v1.2.1