summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_recfunctions.py
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2019-08-16 18:44:10 -0700
committerEric Wieser <wieser.eric@gmail.com>2019-08-19 19:13:22 -0500
commitb7a9378b113da2cb27f40c4f485ffeb225f5d01d (patch)
tree49900aaa3cdf8b30b6ad116ca5a41e13825cf92a /numpy/lib/tests/test_recfunctions.py
parent731127385578fa2cf4e0ad48ef2e456d897d36de (diff)
downloadnumpy-b7a9378b113da2cb27f40c4f485ffeb225f5d01d.tar.gz
BUG: recfunctions: Don't return None in place of empty sequences
Replacing empty tuples with `None` is a bad idea, and just results in an API that is hard to consume - especially since the behavior was never documented. This affects `get_names`, `get_names_flat`, and `get_fieldstructure`.
Diffstat (limited to 'numpy/lib/tests/test_recfunctions.py')
-rw-r--r--numpy/lib/tests/test_recfunctions.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_recfunctions.py b/numpy/lib/tests/test_recfunctions.py
index 11f8a5afa..3b972f4b1 100644
--- a/numpy/lib/tests/test_recfunctions.py
+++ b/numpy/lib/tests/test_recfunctions.py
@@ -113,6 +113,14 @@ class TestRecFunctions(object):
test = get_names(ndtype)
assert_equal(test, ('a', ('b', ('ba', 'bb'))))
+ ndtype = np.dtype([('a', int), ('b', [])])
+ test = get_names(ndtype)
+ assert_equal(test, ('a', ('b', ())))
+
+ ndtype = np.dtype([])
+ test = get_names(ndtype)
+ assert_equal(test, ())
+
def test_get_names_flat(self):
# Test get_names_flat
ndtype = np.dtype([('A', '|S3'), ('B', float)])
@@ -123,6 +131,14 @@ class TestRecFunctions(object):
test = get_names_flat(ndtype)
assert_equal(test, ('a', 'b', 'ba', 'bb'))
+ ndtype = np.dtype([('a', int), ('b', [])])
+ test = get_names_flat(ndtype)
+ assert_equal(test, ('a', 'b'))
+
+ ndtype = np.dtype([])
+ test = get_names_flat(ndtype)
+ assert_equal(test, ())
+
def test_get_fieldstructure(self):
# Test get_fieldstructure
@@ -145,6 +161,11 @@ class TestRecFunctions(object):
'BBA': ['B', 'BB'], 'BBB': ['B', 'BB']}
assert_equal(test, control)
+ # 0 fields
+ ndtype = np.dtype([])
+ test = get_fieldstructure(ndtype)
+ assert_equal(test, {})
+
def test_find_duplicates(self):
# Test find_duplicates
a = ma.array([(2, (2., 'B')), (1, (2., 'B')), (2, (2., 'B')),