Viktor
09/09/2024, 2:29 AMElijah Ben Izzy
09/09/2024, 4:22 AMload_from, and use that node to give you the path.
@load_from.csv(
path=source("path_to_load")
)
def foo(data: pd.DataFrame) -> pd.DataFrame:
...
def path_to_load() -> str:
return "/foo/bar" if os.path.exists("/foo/bar") else ...
You can also define a custom loader class which will encode this…Viktor
09/09/2024, 8:12 AM@load_from.pickle(path=mysource, inject_="test_textwidget_value")
@save_to.pickle(path=mysource, output_name_="textwidget_save")
def test_textwidget(test_textwidget_value: str='') -> str:
...Elijah Ben Izzy
09/09/2024, 1:54 PMNone? Might be a bit cleaner)
3. you’ll need to change the pickle loader class, or add a custom widget loader (load_from.widget)
4. You can do so by registering a loader for pickle (it’ll overwrite the default), and looking at the pickle loader, or by creating a widget loader
5. You shouldElijah Ben Izzy
09/09/2024, 1:54 PMViktor
09/10/2024, 2:21 AMElijah Ben Izzy
09/10/2024, 5:07 PMElijah Ben Izzy
09/11/2024, 4:31 AMNone as well:
@dataclasses.dataclass
class PickleLoader(DataLoader):
path: str
@classmethod
def applicable_types(cls) -> Collection[Type]:
return [object, Any]
@classmethod
def name(cls) -> str:
return "pickle"
def load_data(self, type_: Type[object]) -> Tuple[Optional[object], Dict[str, Any]]:
if not os.path.exists(self.path):
return None
with open(self.path, "rb") as f:
return pickle.load(f), get_file_metadata(self.path)
# make sure you call this code at some point, after importing Hamilton
from hamilton.registry import register_adapter
register_adapter(PickleLoader)
Basically it just overrides the default pickle loaderViktor
09/11/2024, 7:56 PMViktor
09/11/2024, 7:58 PMElijah Ben Izzy
09/11/2024, 8:02 PM