diff options
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/npyio.py | 4 | ||||
-rw-r--r-- | numpy/lib/tests/test_io.py | 23 |
2 files changed, 25 insertions, 2 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index ac71c5b0d..b5723dee5 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -960,8 +960,8 @@ def _read(fname, *, delimiter=',', comment='#', quote='"', if quote is not None: raise ValueError( "when multiple comments or a multi-character comment is " - "given, quotes are not supported. In this case the quote " - "character must be set to the empty string: `quote=''`.") + "given, quotes are not supported. In this case quotechar " + "must be set to None.") if len(imaginary_unit) != 1: raise ValueError('len(imaginary_unit) must be 1.') diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index a0bc2e135..d73d50959 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -3177,3 +3177,26 @@ def test_loadtxt_quote_support_default(): res = np.loadtxt(txt, dtype=dtype, delimiter=",", quotechar='"') assert_array_equal(res, expected) + + +def test_loadtxt_quotechar_multichar_error(): + txt = StringIO("1,2\n3,4") + msg = r".*must be a single unicode character or None" + with pytest.raises(TypeError, match=msg): + np.loadtxt(txt, delimiter=",", quotechar="''") + + +def test_loadtxt_comment_multichar_error_with_quote(): + txt = StringIO("1,2\n3,4") + msg = ( + "when multiple comments or a multi-character comment is given, " + "quotes are not supported." + ) + with pytest.raises(ValueError, match=msg): + np.loadtxt(txt, delimiter=",", comments="123", quotechar='"') + with pytest.raises(ValueError, match=msg): + np.loadtxt(txt, delimiter=",", comments=["#", "%"], quotechar='"') + + # A single character string in a tuple is unpacked though: + res = np.loadtxt(txt, delimiter=",", comments=("#",), quotechar="'") + assert_equal(res, [[1, 2], [3, 4]]) |