diff options
| author | Ross Barnowski <rossbar@berkeley.edu> | 2022-01-10 12:05:13 -0800 |
|---|---|---|
| committer | Sebastian Berg <sebastian@sipsolutions.net> | 2022-01-14 20:07:07 -0600 |
| commit | bbf14c01022023f0be0b3d25af2d315a6e42598e (patch) | |
| tree | 2ac7aec369bd58cdd358e0535dc22c1e5cc3775d /numpy/lib | |
| parent | b670ff7a188bb22ef2dd3437242394a61e805119 (diff) | |
| download | numpy-bbf14c01022023f0be0b3d25af2d315a6e42598e.tar.gz | |
TST: Add tests for quote character support.
Diffstat (limited to 'numpy/lib')
| -rw-r--r-- | numpy/lib/tests/test_io.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index c277f1ddc..97d8f5b14 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -3146,3 +3146,18 @@ def test_loadtxt_converters_dict_raises_val_not_callable(): TypeError, match="values of the converters dictionary must be callable" ): np.loadtxt(StringIO("1 2\n3 4"), converters={0: 1}) + + +@pytest.mark.parametrize("q", ('"', "'", "`")) +def test_loadtxt_quoted_field(q): + txt = TextIO( + f"{q}alpha, x{q}, 2.5\n{q}beta, y{q}, 4.5\n{q}gamma, z{q}, 5.0\n" + ) + dtype = np.dtype([('f0', 'U8'), ('f1', np.float64)]) + expected = np.array( + [("alpha, x", 2.5), ("beta, y", 4.5), ("gamma, z", 5.0)], dtype=dtype + ) + + # Test quote param default + res = np.loadtxt(txt, dtype=dtype, delimiter=",", quotechar=q) + assert_array_equal(res, expected) |
