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

Omegaconf breaks with a custom resolver providing a datetime #3620

Open
ankatiyar opened this issue Feb 14, 2024 · 5 comments
Open

Omegaconf breaks with a custom resolver providing a datetime #3620

ankatiyar opened this issue Feb 14, 2024 · 5 comments
Labels
Issue: Feature Request New feature or improvement to existing feature

Comments

@ankatiyar
Copy link
Contributor

Description

This case came up in a user question (@PetitLepton) - https://linen-slack.kedro.org/t/16417334/hi-folks-i-encountered-an-unexpected-behavior-regarding-the-#8d5f69d7-25ce-409f-b009-0a6a50cd064c

Context

The user has a custom resolver in their config which converts a string to a pandas.Timestamp type -

  • settings.py :
from datetime import timezone

# Third-party
import pandas


def parse_timezone_aware_datetime_string(datetime_string: str) -> pandas.Timestamp:
    timestamp = pandas.Timestamp(datetime_string).astimezone(tz=timezone.utc)
    return timestamp


# Keyword arguments to pass to the `CONFIG_LOADER_CLASS` constructor.
CONFIG_LOADER_ARGS = {
    "custom_resolvers": {
        "parse_timezone_aware_datetime_string": parse_timezone_aware_datetime_string,
    },
    "base_env": "base",
    "default_run_env": "local",
     }
}
  • parameters.yml
start: ${parse_timezone_aware_datetime_string:2023-12-13T23:00:00+01:00}
test: "${runtime_params:the_test,2}"

This works fine when you do a kedro run without any run time parameters but fails with the following error when you do a kedro run --params="the_test=1":

omegaconf.errors.UnsupportedValueType: Value 'datetime' is not a supported primitive type
    full_key: start
    object_type=dict

This is because when there's run time params, there is an additional merge step -

if self._extra_params:
# Merge nested structures
params = OmegaConf.merge(params, self._extra_params)

This happens after the parameter with the custom resolver has already been resolved into the pandas.Timestamp type and omegaconf apparently does not support non primitive types in the config.

Possible Implementation

  • Delay the resolution of the config to after this merge happens in the Context

Possible Alternatives

@noklam
Copy link
Contributor

noklam commented Apr 22, 2024

Should this get moved to discussion or is it ready to be discussed? @ankatiyar

@astrojuanlu
Copy link
Member

This hasn't been discussed yet, it's in the Inbox

@noklam
Copy link
Contributor

noklam commented May 20, 2024

84b3e5c

This was the original PR that creates this regression. The PR was about removing custom syntax, there is a minor refactoring that use OmegaConf to remove the custom nest dict update function. This is the root cause of the bug.

Things to do IMO:

  • Revert back to custom nested dict update
  • Added a regression use case with non-primitive type.

Another way to confirm this is to reproduce the error and run this in older version (maybe 0.18.14)

@PetitLepton
Copy link
Contributor

I am coming back to this as I currently cannot bump our code from 0.18.14 to 0.19.8. A full minimal example is at https://github.com/PetitLepton/kedro-runtime-params.

@noklam
Copy link
Contributor

noklam commented Aug 28, 2024

@PetitLepton thanks for bumping this, I think we have a clear solution here already, which is do not use Omegaconf in KedroContext. I have commented that we should not do this , the simple solution here is to revert to a recursively dict update.

@noklam noklam changed the title Delay the resolution of config/parameters Omegaconf breaks with a custom resolver providing a datetime Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: Feature Request New feature or improvement to existing feature
Projects
Status: No status
Development

No branches or pull requests

4 participants