Skip to content
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

[Feature]: Add dictionary methods to MultiContainerInterface #1161

Open
rly opened this issue Aug 2, 2024 · 1 comment
Open

[Feature]: Add dictionary methods to MultiContainerInterface #1161

rly opened this issue Aug 2, 2024 · 1 comment
Assignees
Labels
category: enhancement improvements of code or code behavior priority: low alternative solution already working and/or relevant to only specific user(s)
Milestone

Comments

@rly
Copy link
Contributor

rly commented Aug 2, 2024

What would you like to see added to HDMF?

Classes that extend MultiContainerInterface gain a __getitem__ which provides a convenient interface for accessing an item within it by name. This works only for MultiContainerInterface classes that have one single multi-container attribute (i.e., a single element in __clsconf__) (code). In PyNWB, that is almost all of them (except for NWBFile and possible extensions).

This allows you to do:

position["spatial_series1"]

Instead of:

position.spatial_series["spatial_series1"]

However, if you want to iterate through the contained objects, you have to use the attribute, which is a labelled dictionary:

for spatial_series_name in position.spatial_series:
    print(spatial_series_name)
for spatial_series in position.spatial_series.values():
    print(spatial_series)

It would be nice to be able to do just:

for spatial_series_name in position:
    print(spatial_series_name)
for spatial_series in position.values():
    print(spatial_series)

What solution would you like?

See above.

Do you have any interest in helping implement the feature?

Yes.

@rly rly added category: enhancement improvements of code or code behavior priority: low alternative solution already working and/or relevant to only specific user(s) labels Aug 2, 2024
@rly rly added this to the Future milestone Aug 2, 2024
@rly
Copy link
Contributor Author

rly commented Aug 2, 2024

This comes from ndx-pose where a TrainingFrame contains a SkeletonInstances object, which is a MultiContainerInterface of SkeletonInstance objects. Iterating through this requires the syntax:

for instance in training_frame.skeleton_instances.skeleton_instances.values()
	print(instance)

The naming makes this even more awkward.

@rly rly self-assigned this Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: enhancement improvements of code or code behavior priority: low alternative solution already working and/or relevant to only specific user(s)
Projects
None yet
Development

No branches or pull requests

1 participant