summaryrefslogtreecommitdiff
path: root/numpy/lib/tests
diff options
context:
space:
mode:
authordmbelov <dmbelov@gmail.com>2023-01-01 07:38:57 -0500
committerGitHub <noreply@github.com>2023-01-01 13:38:57 +0100
commit6d474f2dfe5e4b7ea2a6e7423a638316fa186227 (patch)
treef7b19ec9919f95433e6ee41ebb596d0df28ecd4c /numpy/lib/tests
parent77f15776e1d6d1357cd8c45dd297da821e18e0c2 (diff)
downloadnumpy-6d474f2dfe5e4b7ea2a6e7423a638316fa186227.tar.gz
BUG: np.loadtxt cannot load text file with quoted fields separated by whitespace (#22906)
Fix issue with `delimiter=None` and quote character not working properly (not using whitespace delimiter mode). Closes gh-22899
Diffstat (limited to 'numpy/lib/tests')
-rw-r--r--numpy/lib/tests/test_loadtxt.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_loadtxt.py b/numpy/lib/tests/test_loadtxt.py
index 819a8dda4..8a5b044b8 100644
--- a/numpy/lib/tests/test_loadtxt.py
+++ b/numpy/lib/tests/test_loadtxt.py
@@ -534,6 +534,20 @@ def test_quoted_field(q):
assert_array_equal(res, expected)
+@pytest.mark.parametrize("q", ('"', "'", "`"))
+def test_quoted_field_with_whitepace_delimiter(q):
+ txt = StringIO(
+ 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
+ )
+
+ res = np.loadtxt(txt, dtype=dtype, delimiter=None, quotechar=q)
+ assert_array_equal(res, expected)
+
+
def test_quote_support_default():
"""Support for quoted fields is disabled by default."""
txt = StringIO('"lat,long", 45, 30\n')