summaryrefslogtreecommitdiff
path: root/numpy/lib/tests
diff options
context:
space:
mode:
authorNoƩ Rubinstein <noe.rubinstein@gmail.com>2023-01-27 19:39:38 +0100
committerGitHub <noreply@github.com>2023-01-27 19:39:38 +0100
commit41499995a4c532556b2b6d6e3c0fabb0a7bdb61a (patch)
tree9776bca523d90e02388442a38740a04eb4d41731 /numpy/lib/tests
parent2289292db6a19f2bbfddd3dea3790ffa19955333 (diff)
downloadnumpy-41499995a4c532556b2b6d6e3c0fabb0a7bdb61a.tar.gz
API: Raise EOFError when trying to load past the end of a `.npy` file (#23105)
Currently, the following code: ``` import numpy as np with open('foo.npy', 'wb') as f: for i in range(np.random.randint(10)): np.save(f, 1) with open('foo.npy', 'rb') as f: while True: np.load(f) ``` Will raise: ``` ValueError: Cannot load file containing pickled data when allow_pickle=False ``` While there is no pickled data in the file.
Diffstat (limited to 'numpy/lib/tests')
-rw-r--r--numpy/lib/tests/test_io.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index 4699935ca..cffe7e7ac 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -2737,3 +2737,13 @@ def test_load_refcount():
with assert_no_gc_cycles():
x = np.loadtxt(TextIO("0 1 2 3"), dtype=dt)
assert_equal(x, np.array([((0, 1), (2, 3))], dtype=dt))
+
+def test_load_multiple_arrays_until_eof():
+ f = BytesIO()
+ np.save(f, 1)
+ np.save(f, 2)
+ f.seek(0)
+ assert np.load(f) == 1
+ assert np.load(f) == 2
+ with pytest.raises(EOFError):
+ np.load(f)