1919from boto3 .s3 .transfer import TransferConfig # type: ignore
2020from pandas .io .common import infer_compression # type: ignore
2121
22-
2322from awswrangler import _data_types , _utils , catalog , exceptions
2423
2524_COMPRESSION_2_EXT : Dict [Optional [str ], str ] = {None : "" , "gzip" : ".gz" , "snappy" : ".snappy" }
@@ -291,25 +290,13 @@ def _delete_objects(bucket: str, keys: List[str], client_s3: boto3.client) -> No
291290 _logger .debug ("len(keys): %s" , len (keys ))
292291 batch : List [Dict [str , str ]] = [{"Key" : key } for key in keys ]
293292 res = client_s3 .delete_objects (Bucket = bucket , Delete = {"Objects" : batch })
294- deleted = res .get ('Deleted' )
295- errors = res .get ('Errors' )
296- if errors :
297- for i in errors :
298- raise exceptions .ServiceApiError (
299- 'Path: s3://{}/{}\n '
300- 'Error Code: {}\n '
301- 'Message: {}' .format (
302- bucket ,
303- i .get ('Key' ),
304- i .get ('Code' ),
305- i .get ('Message' )
306- )
307- )
308- else :
293+ deleted = res .get ("Deleted" )
294+ if deleted is not None :
309295 for i in deleted :
310- _logger .debug (
311- 's3://{}/{} has been deleted' .format (bucket , i .get ('Key' ))
312- )
296+ _logger .debug ("s3://%s/%s has been deleted." , bucket , i .get ("Key" ))
297+ errors = res .get ("Errors" )
298+ if errors is not None : # pragma: no cover
299+ raise exceptions .ServiceApiError (errors )
313300
314301
315302def describe_objects (
@@ -1067,7 +1054,7 @@ def to_parquet( # pylint: disable=too-many-arguments
10671054 if compression_ext is None :
10681055 raise exceptions .InvalidCompression (f"{ compression } is invalid, please use None, snappy or gzip." )
10691056 if dataset is False :
1070- if path .endswith ("/" ):
1057+ if path .endswith ("/" ): # pragma: no cover
10711058 raise exceptions .InvalidArgumentValue (
10721059 "If <dataset=False>, the argument <path> should be a object path, not a directory."
10731060 )
@@ -1890,7 +1877,7 @@ def _read_parquet_metadata(
18901877 if isinstance (path , str ):
18911878 _path : Optional [str ] = path if path .endswith ("/" ) else f"{ path } /"
18921879 paths : List [str ] = _path2list (path = _path , boto3_session = session )
1893- else :
1880+ else : # pragma: no cover
18941881 raise exceptions .InvalidArgumentType ("Argument <path> must be str if dataset=True." )
18951882 else :
18961883 if isinstance (path , str ):
@@ -1899,7 +1886,7 @@ def _read_parquet_metadata(
18991886 elif isinstance (path , list ):
19001887 _path = None
19011888 paths = path
1902- else :
1889+ else : # pragma: no cover
19031890 raise exceptions .InvalidArgumentType (f"Argument path must be str or List[str] instead of { type (path )} ." )
19041891 schemas : List [Dict [str , str ]] = [
19051892 _read_parquet_metadata_file (path = x , use_threads = use_threads , boto3_session = session )
@@ -1909,7 +1896,7 @@ def _read_parquet_metadata(
19091896 columns_types : Dict [str , str ] = {}
19101897 for schema in schemas :
19111898 for column , _dtype in schema .items ():
1912- if (column in columns_types ) and (columns_types [column ] != _dtype ):
1899+ if (column in columns_types ) and (columns_types [column ] != _dtype ): # pragma: no cover
19131900 raise exceptions .InvalidSchemaConvergence (
19141901 f"Was detect at least 2 different types in column { column } ({ columns_types [column ]} and { dtype } )."
19151902 )
0 commit comments