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

oc.dict.values/keys support relative keys #942

Closed
ssnl opened this issue May 24, 2022 · 1 comment · Fixed by #946
Closed

oc.dict.values/keys support relative keys #942

ssnl opened this issue May 24, 2022 · 1 comment · Fixed by #946
Labels
bug Something isn't working easy

Comments

@ssnl
Copy link

ssnl commented May 24, 2022

oc.dict.values/keys currently only uses absolute keys, which makes it annoying in implementing some cases, e.g., workaround described in facebookresearch/hydra#1939. However, supporting relative keys are easy (just call _get_full_key())!

@Jasha10 Jasha10 added the enhancement New feature or request label May 24, 2022
@Jasha10 Jasha10 changed the title oc.dict.values/keys` support relative keys oc.dict.values/keys support relative keys May 26, 2022
@Jasha10
Copy link
Collaborator

Jasha10 commented May 26, 2022

It seems that oc.dict.keys does work with relative dotpaths but oc.dict.values does not.

from pytest import raises
from omegaconf import OmegaConf
from omegaconf.errors import InterpolationResolutionError

cfg = OmegaConf.create(
    {
        "workers": {
            "node3": "10.0.0.2",
            "node7": "10.0.0.9",
        },
        "nodes": "${oc.dict.keys: workers}",
        "ips": "${oc.dict.values: workers}",
        "nodes_relative": "${oc.dict.keys: .workers}",
        "ips_relative": "${oc.dict.values: .workers}",
    }
)
assert cfg.nodes[0] == "node3"
assert cfg.ips[0] == "10.0.0.2"
assert cfg.nodes_relative[0] == "node3"
with raises(InterpolationResolutionError):
    cfg.ips_relative[0]

@Jasha10 Jasha10 added bug Something isn't working easy and removed enhancement New feature or request labels May 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working easy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants