| 754 | |
| 755 | |
| 756 | def _savez(file, args, kwds, compress, allow_pickle=True, pickle_kwargs=None): |
| 757 | # Import is postponed to here since zipfile depends on gzip, an optional |
| 758 | # component of the so-called standard library. |
| 759 | import zipfile |
| 760 | |
| 761 | if not hasattr(file, 'write'): |
| 762 | file = os.fspath(file) |
| 763 | if not file.endswith('.npz'): |
| 764 | file = file + '.npz' |
| 765 | |
| 766 | namedict = kwds |
| 767 | for i, val in enumerate(args): |
| 768 | key = f'arr_{i}' |
| 769 | if key in namedict.keys(): |
| 770 | raise ValueError( |
| 771 | f"Cannot use un-named variables and keyword {key}") |
| 772 | namedict[key] = val |
| 773 | |
| 774 | if compress: |
| 775 | compression = zipfile.ZIP_DEFLATED |
| 776 | else: |
| 777 | compression = zipfile.ZIP_STORED |
| 778 | |
| 779 | zipf = zipfile_factory(file, mode="w", compression=compression) |
| 780 | try: |
| 781 | for key, val in namedict.items(): |
| 782 | fname = key + '.npy' |
| 783 | val = np.asanyarray(val) |
| 784 | # always force zip64, gh-10776 |
| 785 | with zipf.open(fname, 'w', force_zip64=True) as fid: |
| 786 | format.write_array(fid, val, |
| 787 | allow_pickle=allow_pickle, |
| 788 | pickle_kwargs=pickle_kwargs) |
| 789 | finally: |
| 790 | zipf.close() |
| 791 | |
| 792 | |
| 793 | def _ensure_ndmin_ndarray_check_param(ndmin): |