Luis Chaves Rodriguez
01/14/2025, 4:36 PMmarimo edit notebooks/nb.py
where my folder structure is something like:
├── README.md
├── conf
│ ├── base
│ ├── local
├── data ...
├── notebooks
│ ├── nb.py
├── pyproject.toml
├── requirements.txt
├── src ...
└── tests ...
Within nb.py
I have a cell that runs:
from kedro.io import DataCatalog
from kedro.config import OmegaConfigLoader
from kedro.framework.project import settings
from pathlib import Path
conf_loader = OmegaConfigLoader(
conf_source=Path(__file__).parent /settings.CONF_SOURCE,
default_run_env = "base"
)
catalog = DataCatalog.from_config(conf_loader["catalog"], credentials=conf_loader["credentials"])
and later...
weekly_sales = pl.from_pandas(
catalog.load("mytable")
)
The issue is, within the catalog
all the filepaths are absolute and assume that wherever the catalog is being used from is using the Kedro project root level. the conf_source
argument in the OmegaConfigLoader
instance is an absolute path (e.g. conf/base/sql/somequery.sql
or data/mydataset.csv
so if I run my notebook from the root of my kedro project, all is fine but I were to run: cd notebooks; marimo edit nb.py
then catalog.load
will attempt to load the query or dataset from notebooks/conf/base/sql/somequery.sql
Is it clear?
PD: please don't ask me why there is SQL code within the conf folder 😅, it's moving soonHall
01/14/2025, 4:36 PMJuan Luis
01/14/2025, 4:40 PMLuis Chaves Rodriguez
01/14/2025, 4:50 PMLuis Chaves Rodriguez
01/14/2025, 5:27 PMLuis Chaves Rodriguez
01/14/2025, 5:35 PMRashida Kanchwala
01/14/2025, 5:36 PMLuis Chaves Rodriguez
01/14/2025, 5:41 PMJuan Luis
01/14/2025, 6:10 PM%load_ext kedro
works, but there's not a good magic-free solution.
@Luis Chaves Rodriguez one thing you can try is to use runtime parameters. in your dataset:
ds:
filepath: ${runtime_params:project_root}/data/01_raw/thing.csv
and then you can specify it as follows:
config_loader = OmegaConfigLoader(..., runtime_params={"project_root": Path(...).to_posix()})
the missing bit then is how to find the Path(...)
to the project root.
https://docs.kedro.org/en/latest/configuration/advanced_configuration.html#how-to-override-configuration-with-[…]rameters-with-the-omegaconfigloader
does this make sense?Luis Chaves Rodriguez
01/14/2025, 6:17 PMPath(...)
correct? Would the catalog.load
respect that?
In my example, would it be the following?
conf_loader = OmegaConfigLoader(
...,
default_run_env = "base",
runtime_params = {"project_root": Path(__file__).parent }
)
If you had to start from scratch how would you fix this? How do other similar projects approach this?Juan Luis
01/14/2025, 6:35 PMLuis Chaves Rodriguez
01/15/2025, 8:47 AMIf you had to start from scratch how would you fix this? How do other similar projects approach this?
Luis Chaves Rodriguez
01/24/2025, 5:52 PM_find_kedro_project
function for this? https://github.com/kedro-org/kedro/blob/46259b9f5b89a226d47e2119afb40ad7b4fa5e63/kedro/utils.py#L66Juan Luis
01/25/2025, 12:14 PMLuis Chaves Rodriguez
01/25/2025, 12:30 PM