Skip to content

Commit

Permalink
Add json.load and pickle.load
Browse files Browse the repository at this point in the history
  • Loading branch information
pooya-mohammadi committed Sep 3, 2024
1 parent 39afe8a commit f32df75
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion deep_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .utils.lib_utils.integeration_utils import import_lazy_module

# Deep Utils version number
__version__ = "1.3.43"
__version__ = "1.3.44"

from .utils.constants import DUMMY_PATH, Backends

Expand Down
15 changes: 12 additions & 3 deletions deep_utils/utils/json_utils/json_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@


class JsonUtils:

@staticmethod
@method_deprecated
def load_json(json_path: Union[str, Path], encoding="utf-8") -> dict:
return JsonUtils.load(json_path=json_path, encoding=encoding)

@staticmethod
def load(json_path: Union[str, Path], encoding="utf-8") -> dict:
"""
Expand Down Expand Up @@ -38,6 +44,9 @@ def dump(
with open(json_path, mode="w", encoding=encoding) as f:
json.dump(json_object, f, ensure_ascii=ensure_ascii)


JsonUtils.load_json = method_deprecated(JsonUtils.load)
JsonUtils.dump_json = method_deprecated(JsonUtils.dump)
@staticmethod
@method_deprecated
def dump_json(
json_path: Union[str, Path], json_object: Union[list, dict], encoding="utf-8", ensure_ascii=True
) -> None:
JsonUtils.dump(json_path=json_path, json_object=json_object, encoding=encoding, ensure_ascii=ensure_ascii)
14 changes: 12 additions & 2 deletions deep_utils/utils/pickle_utils/pickle_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ def load(file_path: str, mode: str = "rb", encoding=""):
with open(file_path, mode=mode) as f:
return pickle.load(f, encoding=encoding)

@staticmethod
@method_deprecated
def load_pickle(file_path: str, mode: str = "rb", encoding=""):
return PickleUtils.load(file_path=file_path, mode=mode, encoding=encoding)

@staticmethod
@method_deprecated
def dump_pickle(file_path: str, file, mode: str = "wb"):
return PickleUtils.dump(file_path=file_path, file=file, mode=mode)


PickleUtils.load_pickle = method_deprecated(PickleUtils.load)
PickleUtils.dump_pickle = method_deprecated(PickleUtils.dump)
if __name__ == '__main__':
PickleUtils.dump_pickle("i.pkl", {1: 1})
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import setuptools

VERSION = "1.3.43"
VERSION = "1.3.44"

long_description = open("Readme.md", mode="r", encoding="utf-8").read()

Expand Down

0 comments on commit f32df75

Please sign in to comment.