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

AttrDict sorts keys on union #576

Closed
1 of 3 tasks
brynpickering opened this issue Feb 27, 2024 · 0 comments · Fixed by #578
Closed
1 of 3 tasks

AttrDict sorts keys on union #576

brynpickering opened this issue Feb 27, 2024 · 0 comments · Fixed by #578
Labels

Comments

@brynpickering
Copy link
Member

What happened?

This is intended behaviour, but it is silent and probably not what we actually want it to do:

Say we have:

foo = AttrDict({"c": 1, "b": 2})
bar = AttrDict({"d": 10, "b": 2, "a": 20})
foo.union(bar, allow_override=True)

We get:

{'c': 1, 'b': 2, 'a': 20, 'd': 10}

I would expect the result to actually be:

{'c': 1, 'b': 2, 'd': 20, 'a': 10}

The reason the keys in bar are being sorted alphabetically is that in AttrDict.union keys_nested is being called, which sorts keys before returning them nested. bar then has its (sorted) keys iterated over to merge into foo, hence why the keys from foo are not sorted.

To achieve what I think would be more intuitive (and more useful when adding user-defined YAML math) behaviour, we should remove key sorting when calling keys_nested.

Which operating systems have you used?

  • macOS
  • Windows
  • Linux

Version

v0.7.0.dev3

Relevant log output

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant