-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Creating a DataTree should not modify parent and children in-place #9196
Comments
Good point, this wasn't really an intentional breaking of that convention on my part. Happy with either / both of your suggestions. I think I originally put parent in the constructor just so that all attributes were present in the signature, but there are multiple other ways to set the parent once the subtree has been created. |
To be clear the aim here is to do both of @shoyer 's suggestions, probably in 2 separate PRs |
I'm just finding this issue now. I Don't know why I didn't see it. I assume, this is going to make a bunch of changes required in the docs. Can you summarize what I'll need to look for?
That assignment to homer will no longer make bart's sibling lisa? |
Yes, you have this correct.
|
This should be closed by #9297. |
* test from #9196 but on TreeNode * move assignment and copying of children to TreeNode constructor * move copy methods over to TreeNode * change copying behaviour to be in line with #9196 * explicitly test that ._copy_subtree works for TreeNode * reimplement ._copy_subtree using recursion * change treenode.py tests to match expected non-in-place behaviour * fix but created in DataTree.__init__ * add type hints for Generic TreeNode back in * update typing of ._copy_node * remove redunant setting of _name
* test from pydata#9196 but on TreeNode * move assignment and copying of children to TreeNode constructor * move copy methods over to TreeNode * change copying behaviour to be in line with pydata#9196 * explicitly test that ._copy_subtree works for TreeNode * reimplement ._copy_subtree using recursion * change treenode.py tests to match expected non-in-place behaviour * fix but created in DataTree.__init__ * add type hints for Generic TreeNode back in * update typing of ._copy_node * remove redunant setting of _name
What is your issue?
This violates the well-established Python convention that functions either have a return value or modify arguments in-place. They never do both.
Examples:
This particularly surprising if a DataTree argument is reused, e.g.,
Here's my suggestion:
DataTree
constructor make shallow copies of itsDataTree
arguments.parent
constructor argument. It is redundant withchildren
, and unlike children, parent nodes don't show up in theDataTree
repr, so it's more surprising to see them copied.CC @TomNicholas
The text was updated successfully, but these errors were encountered: