Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify docs around custom resolvers #3759

Merged
merged 14 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Upcoming Release 0.19.4

## Major features and improvements
* Clarified docs around using custom resolvers without a full Kedro project.
* Improved error message when passing wrong value to node.
* Cookiecutter errors are shown in short format without the `--verbose` flag.
* Kedro commands now work from any subdirectory within a Kedro project.
Expand Down
3 changes: 2 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,11 @@
"https://www.educative.io/blog/advanced-yaml-syntax-cheatsheet#anchors",
# temporarily, until the file actually exists in `main`
"https://github.com/kedro-org/kedro/blob/main/kedro/templates/project/%7B%7B%20cookiecutter.repo_name%20%7D%7D/.flake8",
"https://www.quora.com/What-is-thread-safety-in-Python", # "403 Client Error: Forbidden for url"
]

# Comment out settings to fix Client Rate Limit Error 429
# linkcheck_retries = 5
linkcheck_retries = 5
# linkcheck_rate_limit_timeout = 2.0

html_context = {
Expand Down
21 changes: 17 additions & 4 deletions docs/source/configuration/advanced_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,9 @@ tree .
└── parameters.yml
```

Consider the following `parameters.yml` file and example Python script:

```yaml
# parameters.yml
learning_rate: 0.01
train_test_ratio: 0.7
```
Expand All @@ -342,7 +343,12 @@ config_loader = OmegaConfigLoader(conf_source=".")
# Optionally, you can also use environments
# config_loader = OmegaConfigLoader(conf_source=".", base_env="base", default_run_env="local")

>>> config_loader["parameters"]
print(config_loader["parameters"])
```

If you run it from the same directory where `parameters.yml` placed it gives the following output:

```console
{'learning_rate': 0.01, 'train_test_ratio': 0.7}
```

Expand All @@ -351,8 +357,9 @@ For the full list of features, please refer to [configuration_basics](./configur
### How to use Custom Resolvers with `OmegaConfigLoader`
You can register custom resolvers to use non-primitive types for parameters.

Consider the following `parameters.yml` file an example of Python script for registering a custom resolver:

```yaml
# parameters.yml
polars_float64: "${polars: Float64}"
today: "${today:}"
```
Expand All @@ -368,6 +375,12 @@ custom_resolvers = {"polars": lambda x: getattr(pl, x),

# Register custom resolvers
config_loader = OmegaConfigLoader(conf_source=".", custom_resolvers=custom_resolvers)
>>> print(config_loader["parameters"])

print(config_loader["parameters"])
```

If you run it from the same directory where `parameters.yml` placed it gives the following output:

```console
{'polars_float64': Float64, 'today': datetime.date(2023, 11, 23)}
```