We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
asdf.treeutil.walk_and_modify
The walk_and_modify docs state:
The tree is traversed depth-first, with order specified by the postorder argument.
However the ordering is not as expected for a depth-first search. See the below example.
For postorder=False the walk appears to be breadth-first.
For postorder=True the leaf nodes are walked breadth-first down the tree (not postorder) then the containers are walked up the tree (postorder).
import asdf tree = { 'l0v0': 0, 'l0v1': 1, 'a': { 'l1v0': 10, 'l1v1': 11, 'b': { 'l1v0': 100, 'l1v1': 101, }, }, } def callback(obj): print(obj) return obj asdf.treeutil.walk_and_modify(tree, callback, postorder=False) print("== postorder ==") asdf.treeutil.walk_and_modify(tree, callback, postorder=True)
outputs
{'l0v0': 0, 'l0v1': 1, 'a': {'l1v0': 10, 'l1v1': 11, 'b': {'l1v0': 100, 'l1v1': 101}}} 0 1 {'l1v0': 10, 'l1v1': 11, 'b': {'l1v0': 100, 'l1v1': 101}} 10 11 {'l1v0': 100, 'l1v1': 101} 100 101 == postorder == 0 1 10 11 100 101 {'l1v0': 100, 'l1v1': 101} {'l1v0': 10, 'l1v1': 11, 'b': {'l1v0': 100, 'l1v1': 101}} {'l0v0': 0, 'l0v1': 1, 'a': {'l1v0': 10, 'l1v1': 11, 'b': {'l1v0': 100, 'l1v1': 101}}}
asdf version: main python version: 3.10 operating system: mac osx
The text was updated successfully, but these errors were encountered:
Successfully merging a pull request may close this issue.
Description of the problem
The walk_and_modify docs state:
However the ordering is not as expected for a depth-first search. See the below example.
For postorder=False the walk appears to be breadth-first.
For postorder=True the leaf nodes are walked breadth-first down the tree (not postorder) then the containers are walked up the tree (postorder).
Example of the problem
outputs
System information
asdf version: main
python version: 3.10
operating system: mac osx
The text was updated successfully, but these errors were encountered: