From da668fc74653e5caae9f741461c4d20f9df6e5c1 Mon Sep 17 00:00:00 2001 From: drasmuss Date: Mon, 2 May 2016 17:06:26 -0400 Subject: [PATCH] BUG: Cast size to int64 when loading from archive Prevents overflow errors for large arrays on systems where the default int type is int32. --- numpy/lib/format.py | 2 +- numpy/lib/tests/test_format.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/numpy/lib/format.py b/numpy/lib/format.py index a0f2c5497586..cfe0e62acf33 100644 --- a/numpy/lib/format.py +++ b/numpy/lib/format.py @@ -623,7 +623,7 @@ def read_array(fp, allow_pickle=True, pickle_kwargs=None): if len(shape) == 0: count = 1 else: - count = numpy.multiply.reduce(shape) + count = numpy.multiply.reduce(shape, dtype=numpy.int64) # Now read the actual data. if dtype.hasobject: diff --git a/numpy/lib/tests/test_format.py b/numpy/lib/tests/test_format.py index a091ef5b3fc9..46b21707f83a 100644 --- a/numpy/lib/tests/test_format.py +++ b/numpy/lib/tests/test_format.py @@ -836,5 +836,19 @@ def test_large_file_support(): assert_array_equal(r, d) +@dec.slow +def test_large_archive(): + a = np.empty((2 ** 30, 2), dtype=np.uint8) + fname = os.path.join(tempdir, "large_archive") + + with open(fname, "wb") as f: + np.savez(f, arr=a) + + with open(fname, "rb") as f: + new_a = np.load(f)["arr"] + + assert a.shape == new_a.shape + + if __name__ == "__main__": run_module_suite()