-
Notifications
You must be signed in to change notification settings - Fork 33
Add mixin class for data types with un-named (sub)group properties, e.g. ProcessingModule #705
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
base: main
Are you sure you want to change the base?
Conversation
Try using redefinesParen
Add HasGroup mixin class to classes with anonymous subgroups
Fix HasGroups with redefinesDot. This is one option, but only supported from R2021b and later
Utility method for listing names of generated classes for neurodata types
Add TypeName property as a convenience for getting the short name of a data type
- Renamed to HasUnnamedGroups - Use dynamic props instead of overriding indexing - add "add" method
Use callback functions instead of event listeners. The dependency of container groups and their sets are very specific, and an event/listener system would be too general for this case. I.e a Set does not generally have to notify about Items added/removed.
- Add callback function properties accessible by matnwb.mixin.HasUnnamedGroups - Add add method - Add optional inputs for controlling behavior of set method
Rename and reorder methods for better logical composition
- Add the HasUnnamedGroups mixin to the relevant data type classes
Add minimal support for contained "types.untyped.Anon" objects add and NotImplemented warnings/errors in cases where these are not supported
Suppress warning
Rename variable depnm to superclassNames
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #705 +/- ##
==========================================
- Coverage 95.05% 94.85% -0.21%
==========================================
Files 161 163 +2
Lines 5868 6124 +256
==========================================
+ Hits 5578 5809 +231
- Misses 290 315 +25 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Only invoke callback if the set operation adds a new element, but not for overrides
…thub.com/NeurodataWithoutBorders/matnwb into add-mixin-for-type-with-group-properties
This is currently possible in MatNWB, but creates an invalid group in the NWB-file where two different data type objects are merged in the same ground: nwbFile = tests.factory.NWBFile();
module = types.core.ProcessingModule();
nwbFile.processing.set('test', module);
T = struct2table(struct('name', {'a', 'b'}, 'value', {1, 2}));
dynamicTable = util.table2nwb(T);
nwbFile.processing.get('test').description = 'a test';
nwbFile.processing.get('test').nwbdatainterface.set('test', tests.factory.TimeSeriesWithTimestamps)
nwbFile.processing.get('test').dynamictable.set('test', dynamicTable)
nwbExport( nwbFile, 'test_same_name_in_different_subgroups.nwb') Easy to prevent for this new syntax, but not for the legacy syntax. |
Improve variable naming Remove unused code
Simplify some code sections Create nameExists method to check i name is already used in subgroup containers
Add verification the test that object is added and removed on the underlying subgroup object when using methods on the parent object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- renamed
depnm
tosuperclassNames
- add
matnwb.mixin.HasUnnamedGroups
as superclass to data types with un-named subgroups
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convenience method for listing class names (or short names) of all generated types
Do we need all of this renaming logic? What if someone tries to add two objects, Why can't we just change |
That will look like this: module = types.core.ProcessingModule('description', 'a module with two timeseries');
module.add('time_series', types.core.TimeSeries)
module.add('time-series', types.core.TimeSeries)
>> module
module =
Warning: The following named elements of "ProcessingModule" are remapped to have valid MATLAB names, but will be written to file with
their actual names:
ValidName ActualName
_______________ _____________
"time_series_1" "time-series"
ProcessingModule with properties:
description: 'a module with two timeseries'
time_series_1: [1×1 types.core.TimeSeries]
time_series: [1×1 types.core.TimeSeries] Which is actually quite similar to how MATLAB does it in e.g readtable. given a test.csv file:
>> readtable('test.csv')
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the
table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
ans =
2×2 table
time_series time_series_1
___________ _____________
1 2
3 4
First, I would like to avoid using Implementing parenthesis indexing is quite straightforward with the Also, one syntax for "valid" names and another syntax for other names I think would be confusing. In summary, the renaming logic would provide full support for reading files from pynwb where names are specified with spaces or or other symbols that are not supported in MATLAB but also take care of edge cases like the one you used as an example, and in general be easier to use as there would only be one type of indexing syntax to remember |
You're not warning on the add command? I'm really not into magically renaming. Now the order in which the data elements are added to the file object matters and the user needs to learn the renaming rule. I think |
Good point, there could be an extra warning on the add command.
It's not really renaming, just creating an alias which is used for the dynamic properties that enables dot-indexing and autocompletion. How about keeping/providing both modes? A typical MATLAB user would likely specify names using valid camelCase or snake_case and not encounter the name remapping at all. If they loaded a file created with python using different naming convention, their preferred modes might vary. For example, I prefer to explore new objects in the command window, in which the alias-names are presented and where I can use them for dot-indexing. If someone else prefers to use the "real" names they could do so with |
|
+ unittest + factory functions for new unittest
Motivation
fix #625
How to test the behavior?
Cases to write unit tests for:
Edge cases mentioned in issue
Adding data types to a container type
aProcessingModule.add('namedDataType')
nwbRead
?Removing data types from a container type
Set
object) when using remove on the parent data objectSet
object)Checklist
fix #XX
whereXX
is the issue number?