summaryrefslogtreecommitdiff
path: root/numpy/lib/tests
diff options
context:
space:
mode:
authorSebastian Berg <sebastianb@nvidia.com>2022-12-19 19:40:20 +0100
committerGitHub <noreply@github.com>2022-12-19 10:40:20 -0800
commit5e0ed03b6b7a6ff05843d846eedac730f20decb7 (patch)
treeb96c2745c2354964ca854e5f5169d69dee0112bc /numpy/lib/tests
parentca257565537483ff3b37ab40013f2b7f344e968d (diff)
downloadnumpy-5e0ed03b6b7a6ff05843d846eedac730f20decb7.tar.gz
BUG: Ensure correct behavior for rows ending in delimiter in loadtxt (#22836)
If a row ends in a delimiter, `add_fields` can be called twice without any field actually being parsed. This causes issues with the field buffer setup. closes gh-22833
Diffstat (limited to 'numpy/lib/tests')
-rw-r--r--numpy/lib/tests/test_loadtxt.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_loadtxt.py b/numpy/lib/tests/test_loadtxt.py
index 0b8fe3c47..819a8dda4 100644
--- a/numpy/lib/tests/test_loadtxt.py
+++ b/numpy/lib/tests/test_loadtxt.py
@@ -1011,3 +1011,15 @@ def test_control_characters_as_bytes():
"""Byte control characters (comments, delimiter) are supported."""
a = np.loadtxt(StringIO("#header\n1,2,3"), comments=b"#", delimiter=b",")
assert_equal(a, [1, 2, 3])
+
+
+@pytest.mark.filterwarnings('ignore::UserWarning')
+def test_field_growing_cases():
+ # Test empty field appending/growing (each field still takes 1 character)
+ # to see if the final field appending does not create issues.
+ res = np.loadtxt([""], delimiter=",", dtype=bytes)
+ assert len(res) == 0
+
+ for i in range(1, 1024):
+ res = np.loadtxt(["," * i], delimiter=",", dtype=bytes)
+ assert len(res) == i+1