Skip to content

Commit

Permalink
Added exceptions for invalid paths
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaCappelletti94 committed May 31, 2020
1 parent bfdd410 commit 2d1a167
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion compress_json/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""Current version of package compress_json"""
__version__ = "1.0.3"
__version__ = "1.0.4"
28 changes: 27 additions & 1 deletion compress_json/compress_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ def infer_compression_from_filename(filename: str) -> str:

def dump(obj: Any, path: str, compression_kwargs: Dict = None, json_kwargs: Dict = None):
"""Dump the contents of an object to disk as json, to the supplied path, using the detected compression protocol.
Parameters
----------
----------------
obj: any
The object that will be saved to disk
path: str
Expand All @@ -66,7 +67,14 @@ def dump(obj: Any, path: str, compression_kwargs: Dict = None, json_kwargs: Dict
keywords argument to pass to the compressed file opening protocol.
json_kwargs:
keywords argument to pass to the json file opening protocol.
Raises
----------------
ValueError,
If given path is not a valid string.
"""
if not isinstance(path, str):
raise ValueError("The given path is not a string.")
compression_kwargs = {} if compression_kwargs is None else compression_kwargs
json_kwargs = {} if json_kwargs is None else json_kwargs
compression = infer_compression_from_filename(path)
Expand Down Expand Up @@ -108,7 +116,15 @@ def load(path: str, compression_kwargs: Dict = None, json_kwargs: Dict = None):
keywords argument to pass to the compressed file opening protocol.
json_kwargs:
keywords argument to pass to the json file opening protocol.
Raises
----------------
ValueError,
If given path is not a valid string.
"""
if not isinstance(path, str):
raise ValueError("The given path is not a string.")

compression_kwargs = {} if compression_kwargs is None else compression_kwargs
json_kwargs = {} if json_kwargs is None else json_kwargs
compression = infer_compression_from_filename(path)
Expand Down Expand Up @@ -151,6 +167,11 @@ def local_load(path: str, compression_kwargs: Dict = None, json_kwargs: Dict = N
keywords argument to pass to the compressed file opening protocol.
json_kwargs:
keywords argument to pass to the json file opening protocol.
Raises
----------------
ValueError,
If given path is not a valid string.
"""
return load(local_path(path), compression_kwargs, json_kwargs)

Expand All @@ -168,5 +189,10 @@ def local_dump(obj: Any, path: str, compression_kwargs: Dict = None, json_kwargs
keywords argument to pass to the compressed file opening protocol.
json_kwargs:
keywords argument to pass to the json file opening protocol.
Raises
----------------
ValueError,
If given path is not a valid string.
"""
dump(obj, local_path(path), compression_kwargs, json_kwargs)

0 comments on commit 2d1a167

Please sign in to comment.