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
Add functions to search DictionaryTreeBrowser (e.g. metadata) #2633
Conversation
Codecov Report
@@ Coverage Diff @@
## RELEASE_next_minor #2633 +/- ##
======================================================
+ Coverage 78.97% 79.09% +0.11%
======================================================
Files 206 206
Lines 31868 31907 +39
Branches 7161 7181 +20
======================================================
+ Hits 25169 25238 +69
+ Misses 4939 4910 -29
+ Partials 1760 1759 -1
Continue to review full report at Codecov.
|
How do I add labels to a PR @ericpre @thomasaarholt , do I need extra permissions? |
This would be useful functionality to have but I am not sure if this is a good time to add more functionality to What do you think? |
I've seen #2623 (comment) - but it came only after implementing this one. Couldn't we integrate this functionality anyway at the moment. Should not be a problem to reproduce in the new framework once we move to a new metadata implementation. As far as I can see, neither https://github.com/mewwts/addict nor https://github.com/Infinidat/munch have search capabilities, so it would have to either be contributed there or again implemented on the HyperSpy side. |
Made this PR compatible with the new lazy DTB. Note that as tests were missing, also |
>>> from hyperspy.misc.utils import DictionaryTreeBrowser
>>> tree = DictionaryTreeBrowser(
{
"Node1": {"leaf11": 11,
"Node11": {"leaf111": 111},
},
"Node2": {"leaf21": 21,
"Node21": {"leaf211": 211},
},
})
>>> tree.get_nested_item('Node1.Node11')
>>> tree.get_item('Node1.Node11')
└── leaf111 = 111 In the case above, is it intended that From the API perspective, would it make simple to add this functionality to |
Well, the idea I had in mind was to look for a specific key and therefore looking for a chain of keys does not work.
Would be a possibility. In fact, could even decide automatically based on the length of |
Remains to be done, but could be a useful feature as we are at it.
Implemented like proposed here. |
Partial paths (from the item-key backwards) work as well now. @ericpre could you give this PR another review? |
Description of the change
Add functions
The naming is derived from the
has_item()
andget_item()
functionsMoved
test_dictionary_tree_browser.py
tomisc
folder.Additionally, improved the test coverage of other functions in misc.utils.
Progress of the PR
has_item
andget_item
,CHANGES.rst
,misc.utils
,Minimal example of the bug fix or the new feature
Note that this example can be useful to update the user guide.