3

Is there any option to influence how lists are merged in OmegaConf. Ideally, this could be controlled in the config file, but if there is come switch I can use in the code I'm also interested.

Example:

from omegaconf import OmegaConf

conf1 = OmegaConf.create({"list": [1, 2]})
conf2 = OmegaConf.create({"list": [3, 4]})
conf = OmegaConf.merge(conf1, conf2)
print(conf.pretty())

Output:
list:
- 3
- 4

I'd like to have an option to merge, not override lists (that is, have [1, 2, 3, 4] as a result)

Omry Yadan
  • 31,280
  • 18
  • 64
  • 87
Lesiak
  • 22,088
  • 2
  • 41
  • 65

1 Answers1

2

No. As of OmegaConf 2.0, lists merge is always replacing the target list.

In an early version this used to do what you want, but I chose to go with the current behavior as it seems more useful for lists.

Omry Yadan
  • 31,280
  • 18
  • 64
  • 87
  • 2
    Well, that's an authoritative response. – Lesiak May 23 '20 at 09:23
  • 1
    This might be supported with Structured Configs if/when per-field-metadata is implemented (https://github.com/omry/omegaconf/issues/131) – Omry Yadan May 23 '20 at 16:14
  • 1
    That would be a welcome addition. 99% of the cases you want current behaviour, and then you run across one case when you would like the other – Lesiak May 23 '20 at 19:13
  • 2
    Yup. I will consider it once 131 is implemented. It should be easy enough to add then. – Omry Yadan May 23 '20 at 20:21