8000 BUG: Cast size to int64 when loading from archive · numpy/numpy@da668fc · GitHub
[go: up one dir, main page]

Skip to content

Commit da668fc

Browse files
committed
BUG: Cast size to int64 when loading from archive
Prevents overflow errors for large arrays on systems where the default int type is int32.
1 parent 1fc180b commit da668fc

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

numpy/lib/format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ def read_array(fp, allow_pickle=True, pickle_kwargs=None):
623623
if len(shape) == 0:
624624
count = 1
625625
else:
626-
count = numpy.multiply.reduce(shape)
626+
count = numpy.multiply.reduce(shape, dtype=numpy.int64)
627627

628628
# Now read the actual data.
629629
if dtype.hasobject:

numpy/lib/tests/test_format.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,5 +836,19 @@ def test_large_file_support():
836836
assert_array_equal(r, d)
837837

838838

839+
@dec.slow
840+
def test_large_archive():
841+
a = np.empty((2 ** 30, 2), dtype=np.uint8)
842+
fname = os.path.join(tempdir, "large_archive")
843+
844+
with open(fname, "wb") as f:
845+
np.savez(f, arr=a)
846+
847+
with open(fname, "rb") as f:
848+
new_a = np.load(f)["arr"]
849+
850+
assert a.shape == new_a.shape
851+
852+
839853
if __name__ == "__main__":
840854
run_module_suite()

0 commit comments

Comments
 (0)
0