1

I'd like to control kedro parameters via command line.

According to docs, kedro can specify runtime parameters as follows:

kedro run --params key:value
> {'key': 'value'}

It works. In the same way, I try to specify list parameters like this:

kedro run --params keys:['value1']
> {'keys': '[value1]'}

It doesn't work because kedro interplets not list but str. Probably, this answer could be related.

Hope to mention a couple things to make kedro evaluates list parameters like yaml.

chck
  • 13
  • 3

2 Answers2

3

By default the kedro command line won't typecast parameters beyond simpler numeric types. More complicated parameters should be handled via the parameters.yml file.

That said, if you really want to do this, you can modify your kedro_cli.py to support this. Specifically, you'd want to modify the _split_params callback function in the file. The easiest thing here would likely be to change the line that reads

result[key] = _try_convert_to_numeric(value)

which handles parsing simple numeric types to

result[key] = json.loads(value)

to make it parse a wider range of types. That is, parse the CLI parameter you pass in as json (so you'll also need to be mindful of quotes and making sure that you pass in valid json syntax.

If that doesn't work, you can try adding your own syntax and parsing it in that function. However, my recommendation is to avoid depending on fragile string parameter evaluation from CLI and use the parameters.yml instead.

Zain Patel
  • 983
  • 5
  • 14
  • Thanks for replying. Zain. Just as you said, to pass complicated parameters as cli is incompatible. Especially, in the case of using comma conflicts with default syntax. I’ll take your advice. I’ll always be kedro’s fan. – chck Jun 22 '20 at 11:00
2

In addition to Zain's answer, one can specify extra params using the CLI config. Where config.yml will look something like:

run:
  params:
    keys: [value1]

But to reemphasise: we strongly suggest against adding complex structures in your extra CLI arguments. A suggested way would be to utilise configuration environments for this.

Mariusz
  • 13,481
  • 3
  • 60
  • 64
Dmitry Deryabin
  • 1,518
  • 2
  • 14
  • 27
  • 1
    Thanks for replying, Dmitry. The feature is very cool. It can wrap runtime parameters via config.yml. I'll adopt your way in this case. I will keep your reemphasise in mind:) – chck Jun 22 '20 at 11:00
  • 1
    @Dmitry Deryabin thanks for the answer. Could you please update the CLI config link? Unfortunately it is broken. – evolved Aug 04 '20 at 00:07
  • 1
    @evolved thanks for spotting this! We've reshuffled some of the documentation, which broke the link. The new one is https://kedro.readthedocs.io/en/stable/04_kedro_project_setup/02_configuration.html#configuring-kedro-run-arguments (I'll also update my answer). – Dmitry Deryabin Aug 04 '20 at 09:57