diff --git a/src/datasets/features/image.py b/src/datasets/features/image.py index a399dbf33ea..8bd72c8efaf 100644 --- a/src/datasets/features/image.py +++ b/src/datasets/features/image.py @@ -352,7 +352,7 @@ def encode_np_array(array: np.ndarray) -> dict: def objects_to_list_of_image_dicts( - objs: Union[List[str], List[dict], List[np.ndarray], List["PIL.Image.Image"]] + objs: Union[List[str], List[dict], List[np.ndarray], List["PIL.Image.Image"]], ) -> List[dict]: """Encode a list of objects into a format suitable for creating an extension array of type `ImageExtensionType`.""" if config.PIL_AVAILABLE: diff --git a/src/datasets/utils/hub.py b/src/datasets/utils/hub.py index 0925d075ee0..52b48cec0fe 100644 --- a/src/datasets/utils/hub.py +++ b/src/datasets/utils/hub.py @@ -3,7 +3,7 @@ from huggingface_hub import HfApi, hf_hub_url from packaging import version -from requests import HTTPError +from requests import ConnectionError, HTTPError from .. import config from . import logging @@ -18,15 +18,17 @@ def preupload_lfs_files(hf_api: HfApi, **kwargs): max_retries = 5 base_wait_time = 1 max_wait_time = 8 - status_codes = [500, 503] retry = 0 while True: try: hf_api.preupload_lfs_files(**kwargs) - except (RuntimeError, HTTPError) as err: - if isinstance(err, RuntimeError) and isinstance(err.__cause__, HTTPError): - err = err.__cause__ - if retry >= max_retries or err.response.status_code not in status_codes: + except (RuntimeError, HTTPError, ConnectionError) as err: + if isinstance(err, RuntimeError): + if isinstance(err.__cause__, (HTTPError, ConnectionError)): + err = err.__cause__ + else: + raise err + if retry >= max_retries or err.response and err.response.status_code not in [500, 503]: raise err else: sleep_time = min(max_wait_time, base_wait_time * 2**retry) # Exponential backoff