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 9 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
23 changes: 18 additions & 5 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,17 +343,23 @@ 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"]
{'learning_rate': 0.01, 'train_test_ratio': 0.7}
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}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{'learning_rate': 0.01, 'train_test_ratio': 0.7}}
{'learning_rate': 0.01, 'train_test_ratio': 0.7}

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, thank you

```

For the full list of features, please refer to [configuration_basics](./configuration_basics.md) and [advanced_configuration](./advanced_configuration.md)

### 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)}
```