(file, args, kwds, compress, allow_pickle=True, pickle_kwargs=None)
| 711 | |
| 712 | |
| 713 | def _savez(file, args, kwds, compress, allow_pickle=True, pickle_kwargs=None): |
| 714 | # Import is postponed to here since zipfile depends on gzip, an optional |
| 715 | # component of the so-called standard library. |
| 716 | import zipfile |
| 717 | |
| 718 | if not hasattr(file, 'write'): |
| 719 | file = os_fspath(file) |
| 720 | if not file.endswith('.npz'): |
| 721 | file = file + '.npz' |
| 722 | |
| 723 | namedict = kwds |
| 724 | for i, val in enumerate(args): |
| 725 | key = 'arr_%d' % i |
| 726 | if key in namedict.keys(): |
| 727 | raise ValueError( |
| 728 | "Cannot use un-named variables and keyword %s" % key) |
| 729 | namedict[key] = val |
| 730 | |
| 731 | if compress: |
| 732 | compression = zipfile.ZIP_DEFLATED |
| 733 | else: |
| 734 | compression = zipfile.ZIP_STORED |
| 735 | |
| 736 | zipf = zipfile_factory(file, mode="w", compression=compression) |
| 737 | |
| 738 | for key, val in namedict.items(): |
| 739 | fname = key + '.npy' |
| 740 | val = np.asanyarray(val) |
| 741 | # always force zip64, gh-10776 |
| 742 | with zipf.open(fname, 'w', force_zip64=True) as fid: |
| 743 | format.write_array(fid, val, |
| 744 | allow_pickle=allow_pickle, |
| 745 | pickle_kwargs=pickle_kwargs) |
| 746 | |
| 747 | zipf.close() |
| 748 | |
| 749 | |
| 750 | def _ensure_ndmin_ndarray_check_param(ndmin): |
no test coverage detected