Dump keys and items to an npz file. Args: npz_path (str): Path to a dumped npz file. overwrite (bool, optional): Whether to overwrite if there is already a file. Defaults to True. Raises: ValueError
(self, npz_path: str, overwrite: bool = True)
| 87 | self.__set_default_values__() |
| 88 | |
| 89 | def dump(self, npz_path: str, overwrite: bool = True): |
| 90 | """Dump keys and items to an npz file. |
| 91 | |
| 92 | Args: |
| 93 | npz_path (str): |
| 94 | Path to a dumped npz file. |
| 95 | overwrite (bool, optional): |
| 96 | Whether to overwrite if there is already a file. |
| 97 | Defaults to True. |
| 98 | |
| 99 | Raises: |
| 100 | ValueError: |
| 101 | npz_path does not end with '.npz'. |
| 102 | FileExistsError: |
| 103 | When overwrite is False and file exists. |
| 104 | """ |
| 105 | if not check_path_suffix(npz_path, ['.npz']): |
| 106 | raise ValueError('Not an npz file.') |
| 107 | if not overwrite: |
| 108 | if check_path_existence(npz_path, 'file') == Existence.FileExist: |
| 109 | raise FileExistsError |
| 110 | dict_to_dump = { |
| 111 | '__key_strict__': self.__key_strict__, |
| 112 | '__data_len__': self.__data_len__, |
| 113 | '__instance_num__': self.__instance_num__, |
| 114 | '__keypoints_compressed__': self.__keypoints_compressed__, |
| 115 | } |
| 116 | dict_to_dump.update(self) |
| 117 | np.savez_compressed(npz_path, **dict_to_dump) |
| 118 | |
| 119 | def dump_by_pickle(self, pkl_path: str, overwrite: bool = True) -> None: |
| 120 | """Dump keys and items to a pickle file. It's a secondary dump method, |
no test coverage detected