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

Integer as dict key #149

Closed
noklam opened this issue Feb 7, 2020 · 6 comments
Closed

Integer as dict key #149

noklam opened this issue Feb 7, 2020 · 6 comments
Labels
enhancement New feature or request
Milestone

Comments

@noklam
Copy link

noklam commented Feb 7, 2020

I get this error when using int as dictkey in config, is this being blocked for specific reason? If I remove the assert statement I can run successfully.

I encounter this error when I use facebookresearch/hydra, which depends on omegaconf

from omegaconf import OmegaConf
conf = OmegaConf.create( dict([(1, 2), (3, 4)]))
print(conf.pretty())  

File "C:\ProgramData\Anaconda3\lib\site-packages\omegaconf\dictconfig.py", line 35, in setitem
assert isinstance(key, str)
AssertionError

@omry
Copy link
Owner

omry commented Feb 7, 2020

As you have noted, integers are not supported as dictionary keys in OmegaConf.
This is something I will consider for the version after 2.0.0. which already adds a lot of new surface area.
As a temporary solution, do not use int keys (you convert them to string somehow, maybe like:

1_: foo
2_: bar

the keys should now be strings.
Definitely look at 2.0.0 (docs), it adds support for Enum as keys which may be even better for you. don't try 2.0.0 with stable Hydra, they are incompatible (Integration is still work in progress).

@noklam
Copy link
Author

noklam commented Feb 7, 2020

@omry Thanks for the quick response! Ok I guess I will try convert it into string for now.

@omry omry added this to the OmegaConf 2.1 milestone Mar 6, 2020
@omry omry added the enhancement New feature or request label Mar 24, 2020
@Jasha10
Copy link
Collaborator

Jasha10 commented Dec 11, 2020

I've submitted PR #454 related to this issue.
Before moving further with test coverage, here is a design question:
will we want to support other primitive key types besides int?
Currently (before the above PR), DictConfig keys can be one of
[Any, str, Enum, None]
and DictConfig values can be one of
[Any, str, float, bool, int, None, StructuredConfig].

@omry
Copy link
Owner

omry commented Dec 12, 2020

Let's move the discussion to the PR.

@Jasha10
Copy link
Collaborator

Jasha10 commented Jan 21, 2021

I think this can be closed now.

@omry
Copy link
Owner

omry commented Jan 21, 2021

Yup.

@omry omry closed this as completed Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants