Skip to content

Commit

Permalink
Fixes #1240
Browse files Browse the repository at this point in the history
The cache store assumed that every persister took a `path` argument. That is
not the case because the savers / loaders wrap external APIs and we decided
to not try to create our own abstraction layer around them, and instead mirror them.

E.g. polars takes `file`, but pandas takes `path`.
  • Loading branch information
skrawcz committed Nov 24, 2024
1 parent 0bbc7f8 commit 2e46872
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions hamilton/caching/stores/file.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import inspect
import shutil
from pathlib import Path
from typing import Any, Optional
Expand Down Expand Up @@ -68,8 +69,24 @@ def set(
if saver_cls is not None:
# materialized_path
materialized_path = self._materialized_path(data_version, saver_cls)
saver = saver_cls(path=str(materialized_path.absolute()))
loader = loader_cls(path=str(materialized_path.absolute()))
saver_argspec = inspect.getfullargspec(saver_cls.__init__)
loader_argspec = inspect.getfullargspec(loader_cls.__init__)
if "file" in saver_argspec.args:
saver = saver_cls(file=str(materialized_path.absolute()))
elif "path" in saver_argspec.args:
saver = saver_cls(path=str(materialized_path.absolute()))
else:
raise ValueError(
f"Saver [{saver_cls.name()}] must have either `file` or `path` as an argument."
)
if "file" in loader_argspec.args:
loader = loader_cls(file=str(materialized_path.absolute()))
elif "path" in loader_argspec.args:
loader = loader_cls(path=str(materialized_path.absolute()))
else:
raise ValueError(
f"Loader [{loader_cls.name()}] must have either `file` or `path` as an argument."
)
else:
saver = None
loader = None
Expand Down

0 comments on commit 2e46872

Please sign in to comment.