MCPcopy Create free account
hub / github.com/BIT-DataLab/LakeBench / pickle_python_object

Function pickle_python_object

union/D3L/d3l/utils/functions.py:47–72  ·  view source on GitHub ↗

Save the given Python object to the given path. Parameters ---------- obj : Any Any *picklable* Python object. object_path : str The path where the object will be saved. Returns -------

(obj: Any, object_path: str)

Source from the content-addressed store, hash-verified

45
46
47def pickle_python_object(obj: Any, object_path: str):
48 """
49 Save the given Python object to the given path.
50
51 Parameters
52 ----------
53 obj : Any
54 Any *picklable* Python object.
55 object_path : str
56 The path where the object will be saved.
57
58 Returns
59 -------
60
61 """
62 parent_dir = "/".join(object_path.split("/")[:-1])
63 if not os.path.exists(parent_dir):
64 os.makedirs(parent_dir)
65
66 try:
67 with open(object_path, "wb") as save_file:
68 pickle.dump(obj, save_file)
69 except Exception:
70 raise pickle.PicklingError(
71 "Failed to save object {} to {}!".format(str(obj), object_path)
72 )
73
74
75def unpickle_python_object(object_path: str) -> Any:

Callers 5

indexing_large.pyFile · 0.90
indexing.pyFile · 0.90
mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected