Forbid path-like DataTree child names #9490 #11014
Open
+33
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
DataTreecauses aRecursionError#9978whats-new.rstAddresses #9490 and #9978 by forbidding the
/character inDataTreechild names.DataTreenode names are already checked using_validate_namefrom thetreenodemodule. I therefore call this function inside the_check_childrenmember function ofTreeNode. This check ensures invalidchildrenarguments are caught early in theDataTreeconstructor, and when theDataTree.childrenattribute is reset explicitly (see Set child nodes via DataTree.children #9441). I have also reworded the_validate_nameerror message slightly for consistency with_check_for_slashes_in_names(defined in thedatatreemodule) which checks variable names. To illustrate, code like_check_childrenon the inputchildrenmapping given to theDataTreeconstructor, before it is assigned and the setter function is called. This additional check ensures that if the user passes a badchildren, a helpful error message is given before the shallow copy{name: child.copy() for name, child in children.items()}fails.DataTree.__init__docstring to communicate that/characters are forbidden in both thenameargument, and the keys of thechildrenmapping argument.Additional Notes
This PR follows after discussion with @TomNicholas in #11001. See also #9441 and #9477.