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

repro: Cannot interpolate data of type 'list' #8372

Closed
TheFirstMe opened this issue Sep 28, 2022 · 4 comments
Closed

repro: Cannot interpolate data of type 'list' #8372

TheFirstMe opened this issue Sep 28, 2022 · 4 comments
Labels
A: templating Related to the templating feature feature request Requesting a new feature

Comments

@TheFirstMe
Copy link

TheFirstMe commented Sep 28, 2022

This is a sample of my dvc.yaml.

stages:
    train:
        cmd: python train.py --list ${base.list}

and my params.yaml looks like this:

base:
    loglevel: INFO
    list: ['a', 'b', 'c']
    random_key: random_value

dvc repro currently results in this error:

ERROR: failed to parse 'stages.train.cmd' in 'dvc.yaml':              
Cannot interpolate data of type 'list'

The expected command is python train.py --list 'a' 'b' 'c'

@TheFirstMe TheFirstMe changed the title Cannot interpolate data of type 'list' dvc.yaml: Cannot interpolate data of type 'list' Sep 28, 2022
@TheFirstMe TheFirstMe changed the title dvc.yaml: Cannot interpolate data of type 'list' repro: Cannot interpolate data of type 'list' Sep 28, 2022
@pmrowla pmrowla added the A: templating Related to the templating feature label Sep 28, 2022
@pmrowla
Copy link
Contributor

pmrowla commented Sep 28, 2022

Related: #6107

@pmrowla pmrowla added the feature request Requesting a new feature label Sep 28, 2022
@daavoo
Copy link
Contributor

daavoo commented Sep 28, 2022

@TheFirstMe You can workaround this with https://dvc.org/doc/user-guide/project-structure/dvcyaml-files#dict-unpacking if you wrap the list inside a dict:

dict:
    list: ['a', 'b', 'c']
stages:
    train:
        cmd: python train.py ${dict}

@TheFirstMe
Copy link
Author

@TheFirstMe You can workaround this with https://dvc.org/doc/user-guide/project-structure/dvcyaml-files#dict-unpacking if you wrap the list inside a dict:

dict:
    list: ['a', 'b', 'c']
stages:
    train:
        cmd: python train.py ${dict}

Yes, I am currently doing something like this. But the parameter list is something that will be accessed by multiple stages so I wanted to keep it under a common section (base).

@CarMiranda
Copy link

@TheFirstMe does something like the following serves your purpose?

# params.yaml
base:
  loglevel: INFO
  list:
    list: ['a', 'b', 'c']
  random-key: 0.1

stage1:
  param1: 0.1
  param2: 0.2
  param3: 0.3

stage2:
  param1: 0.3
  param2: 0.2
# dvc.yaml
stages:
  stage1:
    cmd: >-
      python script.py
      ${stage1}
      ${base.list}
      --random-key ${base.random-key}
      --log-level ${base.loglevel}
    deps:
      - script.py
  stage2:
    cmd: >-
      python script.py
      ${stage2}
      ${base.list}
      --random-key ${base.random-key}
      --log-level ${base.loglevel}
    deps:
      - script.py

As you can see, the common parameters remain under the base key, but list is replaced by list: list: [...] which allows to interpolate in the common manner. However, in this way, one cannot expect to interpolate ${base}, which is why the other parameters are specified in the commands.

If you really do not want to write the other parameters, you can simply group them in another key, within the same (or another) dictionary:

base:
  list:
    list: ['a', 'b', 'c']
  others:
    log-level: INFO
    random-key: 0.1

# ...
stages:
  stage1:
    cmd: >-
      python script.py
      ${stage1}
      ${base.list}
      ${base.others}
    deps:
      - script.py
# ...

This is a workaround, I would expect for plain list interpolation to land some time in the (near?) future.

@mattseddon mattseddon closed this as not planned Won't fix, can't repro, duplicate, stale Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A: templating Related to the templating feature feature request Requesting a new feature
Projects
None yet
Development

No branches or pull requests

5 participants