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

Set child nodes via DataTree.children #9441

Open
TomNicholas opened this issue Sep 7, 2024 · 0 comments · May be fixed by #9477
Open

Set child nodes via DataTree.children #9441

TomNicholas opened this issue Sep 7, 2024 · 0 comments · May be fixed by #9477
Labels
enhancement topic-DataTree Related to the implementation of a DataTree class

Comments

@TomNicholas
Copy link
Member

TomNicholas commented Sep 7, 2024

What is your issue?

I realised that if you want to add new children to a DataTree object, then while this works

dt[name] = new_child

and you can examine the children using

dt.children # returns {'name': child1, ...}

then actually this does not currently work

dt.children[name] = new_child

It would be nice to make this work, as I think setting with .children makes the intent much clearer.

It doesn't work because .children is a property that returns a dict - the only way you can update the .children is by replacing it entirely using the property setter, i.e.

dt.children = {'name': new_child}

This problem is analogous to how Dataset has ds.coords, which returns a proxy mapping object which has a __setitem__ method that allow modification in-place.

sort of related to #9204 , and came up whilst doing #9297

cc @shoyer

@TomNicholas TomNicholas added enhancement topic-DataTree Related to the implementation of a DataTree class labels Sep 7, 2024
@TomNicholas TomNicholas linked a pull request Sep 11, 2024 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement topic-DataTree Related to the implementation of a DataTree class
Projects
Development

Successfully merging a pull request may close this issue.

1 participant