Skip to content

Commit

Permalink
refactor: improve error types raised
Browse files Browse the repository at this point in the history
  • Loading branch information
sqr00t committed Oct 31, 2023
1 parent f69e116 commit 8bb5380
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions nesta_ds_utils/loading_saving/S3.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _df_to_fileobj(df_data: pd.DataFrame, path_to: str, **kwargs) -> io.BytesIO:
elif fnmatch(path_to, "*.xlsm"):
df_data.to_excel(buffer, **kwargs)
else:
raise Exception(
raise NotImplementedError(
"Uploading dataframe currently supported only for 'csv', 'parquet', 'xlsx' and xlsm'."
)
buffer.seek(0)
Expand All @@ -72,7 +72,7 @@ def _gdf_to_fileobj(df_data: gpd.GeoDataFrame, path_to: str, **kwargs) -> io.Byt
if fnmatch(path_to, "*.geojson"):
df_data.to_file(buffer, driver="GeoJSON", **kwargs)
else:
raise Exception(
raise NotImplementedError(
"Uploading geodataframe currently supported only for 'geojson'."
)
buffer.seek(0)
Expand Down Expand Up @@ -107,13 +107,13 @@ def _dict_to_fileobj(dict_data: dict, path_to: str, **kwargs) -> io.BytesIO:
]:
buffer.write(json.dumps(dict_data, **kwargs).encode())
else:
raise Exception(
raise AttributeError(
"GeoJSONS must have a member with the name 'type', the value of the member must "
"be one of the following: 'Point', 'MultiPoint', 'LineString', 'MultiLineString',"
"'Polygon', 'MultiPolygon','GeometryCollection', 'Feature' or 'FeatureCollection'."
)
else:
raise Exception(
raise NotImplementedError(
"Uploading dictionary currently supported only for 'json' and 'geojson'."
)
buffer.seek(0)
Expand All @@ -139,7 +139,7 @@ def _list_to_fileobj(list_data: list, path_to: str, **kwargs) -> io.BytesIO:
elif fnmatch(path_to, "*.json"):
buffer.write(json.dumps(list_data, **kwargs).encode())
else:
raise Exception(
raise NotImplementedError(
"Uploading list currently supported only for 'csv', 'txt' and 'json'."
)
buffer.seek(0)
Expand Down Expand Up @@ -408,15 +408,15 @@ def download_obj(
)
return _fileobj_to_dict(fileobj, path_from, **kwargs_reading)
else:
raise Exception(
raise NotImplementedError(
"Download as dictionary currently supported only "
"for 'json' and 'geojson'."
)
elif download_as == "list":
if path_from.endswith(tuple([".csv", ".txt", ".json"])):
return _fileobj_to_list(fileobj, path_from, **kwargs_reading)
else:
raise Exception(
raise NotImplementedError(
"Download as list currently supported only "
"for 'csv', 'txt' and 'json'."
)
Expand Down

0 comments on commit 8bb5380

Please sign in to comment.