Add method to find objects of a given neurodata type#2189
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #2189 +/- ##
=======================================
Coverage 95.18% 95.19%
=======================================
Files 30 30
Lines 2991 2997 +6
Branches 444 445 +1
=======================================
+ Hits 2847 2853 +6
Misses 86 86
Partials 58 58
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@h-mayorquin this looks like something we probably would want to add on |
|
The original PR supports matching both by class and by string (e.g. We could support the basic matching with class only in hdmf and then a method here can use that functionality and add the string matching, concretely: # hdmf (no nwb type map knowledge)
def collect_descendants_of_type(self, type_):
return [obj for obj in self.all_children()
if obj is not self and isinstance(obj, type_)]# pynwb (add string resolution support)
def collect_descendants_of_type(self, neurodata_type):
if isinstance(neurodata_type, str):
neurodata_type = self._get_type_map().get_dt_container_cls(neurodata_type)
return super().collect_descendants_of_type(neurodata_type)One thing that I don't like is that the hdmf loses support for the pattern that @rly described (filtering objects whose Python class was auto-generated from a cached extension namespace at read time), and we have two slightly different functions in pynwb and hdmf which might be surprising and confusing. This compels me to ask: besides the logical place for a thing to be, what would be the concrete gain of having a reduced version on hdmf? |
This PR tries to complete the work started on PR #1737. It implements a couple of the design points raised in the previous discussion:
NWBContainerrather than onNWBFiledirectly, so it works on any sub-container (ProcessingModule,LFP, etc.) and is correctly scoped to that container's subtree.pynwb.get_type_map(copy=False), the live process-wide TypeMap (available since Remove unnecessary calls to deepcopy(get_type_map) #2121), rather thanself.io.manager.type_map; the previous approach required the container to have been read or written through an IO, captured a snapshot of the TypeMap at IO-construction time, and so failed on in-memory containers and missed extensions loaded later in the same process.Fix #560
Checklist
ruff check . && codespellfrom the source directory.