Skip to content

Commit a9f3179

Browse files
yarikopticjaimefrio
authored andcommitted
ENH: for savez create temporary file alongside with the target file
Closes: numpygh-5336
1 parent 231c180 commit a9f3179

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎numpy/lib/npyio.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,11 @@ def _savez(file, args, kwds, compress, allow_pickle=True, pickle_kwargs=None):
627627
zipf = zipfile_factory(file, mode="w", compression=compression)
628628

629629
# Stage arrays in a temporary file on disk, before writing to zip.
630-
fd, tmpfile = tempfile.mkstemp(suffix='-numpy.npy')
630+
631+
# Since target file might be big enough to exceed capacity of a global
632+
# temporary directory, create temp file side-by-side with the target file.
633+
file_path, file_name = os.path.split(file)
634+
fd, tmpfile = tempfile.mkstemp(prefix=file_name, dir=file_path, suffix='-numpy.npy')
631635
os.close(fd)
632636
try:
633637
for key, val in namedict.items():

0 commit comments

Comments
 (0)