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

Function unpickle_python_object

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

Load the Python object from the given path. Parameters ---------- object_path : str The path where the object is saved. Returns ------- Any The object existing at the provided location.

(object_path: str)

Source from the content-addressed store, hash-verified

73
74
75def unpickle_python_object(object_path: str) -> Any:
76 """
77 Load the Python object from the given path.
78
79 Parameters
80 ----------
81 object_path : str
82 The path where the object is saved.
83
84 Returns
85 -------
86 Any
87 The object existing at the provided location.
88
89 """
90 if not os.path.isfile(object_path):
91 raise FileNotFoundError("File {} does not exist locally!".format(object_path))
92 try:
93 with open(object_path, "rb") as save_file:
94 obj = pickle.load(save_file)
95 except Exception:
96 raise pickle.UnpicklingError(
97 "Failed to load object from {}!".format(object_path)
98 )
99 return obj

Calls

no outgoing calls

Tested by

no test coverage detected