diff options
| author | Ross Barnowski <rossbar@berkeley.edu> | 2022-01-10 12:37:32 -0800 |
|---|---|---|
| committer | Sebastian Berg <sebastian@sipsolutions.net> | 2022-01-14 20:07:07 -0600 |
| commit | ff5eb6406a80d7858b93516f96f3e76f57236eb3 (patch) | |
| tree | f4bbad8012ec9d97f730a6997b8cacc2d06a5109 /numpy/lib/tests | |
| parent | 2912231adb4b4b1a89a48277d352f9c93248282f (diff) | |
| download | numpy-ff5eb6406a80d7858b93516f96f3e76f57236eb3.tar.gz | |
TST: structured dtype w/ quotes.
Diffstat (limited to 'numpy/lib/tests')
| -rw-r--r-- | numpy/lib/tests/test_io.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index d73d50959..32beddfdb 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -3200,3 +3200,32 @@ def test_loadtxt_comment_multichar_error_with_quote(): # A single character string in a tuple is unpacked though: res = np.loadtxt(txt, delimiter=",", comments=("#",), quotechar="'") assert_equal(res, [[1, 2], [3, 4]]) + + +def test_loadtxt_structured_dtype_with_quotes(): + data = TextIO( + ( + "1000;2.4;'alpha';-34\n" + "2000;3.1;'beta';29\n" + "3500;9.9;'gamma';120\n" + "4090;8.1;'delta';0\n" + "5001;4.4;'epsilon';-99\n" + "6543;7.8;'omega';-1\n" + ) + ) + dtype = np.dtype( + [('f0', np.uint16), ('f1', np.float64), ('f2', 'S7'), ('f3', np.int8)] + ) + expected = np.array( + [ + (1000, 2.4, "alpha", -34), + (2000, 3.1, "beta", 29), + (3500, 9.9, "gamma", 120), + (4090, 8.1, "delta", 0), + (5001, 4.4, "epsilon", -99), + (6543, 7.8, "omega", -1) + ], + dtype=dtype + ) + res = np.loadtxt(data, dtype=dtype, delimiter=";", quotechar="'") + assert_array_equal(res, expected) |
