From a54a0bdc89dd82ca3cfee89ae70a7fe3ee00e2a2 Mon Sep 17 00:00:00 2001 From: Mark Wiebe Date: Thu, 18 Aug 2011 20:37:36 -0700 Subject: BUG: loadtxt: There was some extra nesting for subarray dtypes (Ticket #1936) --- numpy/lib/tests/test_regression.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'numpy/lib/tests') diff --git a/numpy/lib/tests/test_regression.py b/numpy/lib/tests/test_regression.py index c0cfff9a5..c244aea87 100644 --- a/numpy/lib/tests/test_regression.py +++ b/numpy/lib/tests/test_regression.py @@ -202,5 +202,25 @@ class TestRegression(TestCase): except: raise AssertionError() + def test_loadtxt_fields_subarrays(self): + # For ticket #1936 + from StringIO import StringIO + dt = [("a", 'u1', 2), ("b", 'u1', 2)] + x = np.loadtxt(StringIO("0 1 2 3"), dtype=dt) + assert_equal(x, np.array([((0, 1), (2, 3))], dtype=dt)) + + dt = [("a", [("a", 'u1', (1,3)), ("b", 'u1')])] + x = np.loadtxt(StringIO("0 1 2 3"), dtype=dt) + assert_equal(x, np.array([(((0,1,2), 3),)], dtype=dt)) + + dt = [("a", 'u1', (2,2))] + x = np.loadtxt(StringIO("0 1 2 3"), dtype=dt) + assert_equal(x, np.array([(((0, 1), (2, 3)),)], dtype=dt)) + + dt = [("a", 'u1', (2,3,2))] + x = np.loadtxt(StringIO("0 1 2 3 4 5 6 7 8 9 10 11"), dtype=dt) + data = [((((0,1), (2,3), (4,5)), ((6,7), (8,9), (10,11))),)] + assert_equal(x, np.array(data, dtype=dt)) + if __name__ == "__main__": run_module_suite() -- cgit v1.2.1