Accept zarr v3 arrays in array-valued fields; fix ElectricalSeries len() - #2235
Open
rly wants to merge 2 commits into
Open
Accept zarr v3 arrays in array-valued fields; fix ElectricalSeries len()#2235rly wants to merge 2 commits into
rly wants to merge 2 commits into
Conversation
Retype the array-valued fields declared collections.abc.Iterable to the
('array_data', 'data') docval type so array-API arrays such as a zarr v3
Array (which implement neither __iter__ nor __len__) are accepted on read:
TimeSeries.control/control_description, ImageSeries.dimension/starting_frame,
AbstractFeatureSeries.features/feature_units, and the deprecated
Clustering.peak_over_rms and ClusterWaveforms.waveform_mean/waveform_sd.
NWBFile.electrode_groups stays Iterable; it holds ElectrodeGroup objects,
not array data.
Derive the electrode count in ElectricalSeries.__init__ from get_data_shape
instead of len(electrodes.data), which raised TypeError on a zarr v3 Array.
See #2234.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #2235 +/- ##
==========================================
- Coverage 96.02% 96.02% -0.01%
==========================================
Files 30 30
Lines 2997 2995 -2
Branches 436 436
==========================================
- Hits 2878 2876 -2
Misses 67 67
Partials 52 52
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Fixes #2234.
Reading NWB files through the zarr backend (hdmf-zarr's zarr v3 migration) passes lazily-read datasets into container constructors as raw
zarr.Arrayobjects. A zarr v3Arrayimplements neither__iter__nor__len__, which broke pynwb in two places:type=collections.abc.Iterablerejected zarr arrays, becauseisinstance(zarr_array, Iterable)isFalse(the ABC only recognizes__iter__; iteration otherwise works via the__getitem__sequence protocol).ElectricalSeries.__init__calledlen(electrodes.data)directly, raisingTypeError: object of type 'Array' has no len().hdmf already accepts zarr v3 arrays in its own type system (it registers
zarr.Arrayin thearray_datadocval macro), so both issues are pynwb-side.Changes
Iterableto('array_data', 'data'):TimeSeries.control/control_description,ImageSeries.dimension/starting_frame,AbstractFeatureSeries.features/feature_units, and the deprecatedClustering.peak_over_rms,ClusterWaveforms.waveform_mean/waveform_sd(still constructed on read).NWBFile.electrode_groupsasIterable: it holdsElectrodeGroupobjects, not array data, and is never backed by a dataset.ElectricalSeries.__init__, derive the electrode count viaget_data_shape(...)[0]instead oflen(electrodes.data), matching the pattern already used fordata.tests/unit/test_array_data_fields.pyguarding the retype (array accepted, non-array iterable rejected) and theelectrode_groupsexclusion.Behavior change
('array_data', 'data')acceptszarr.Arraybut does not accept non-array iterables (str,set,range, generators) for these fields, whichIterablepreviously allowed. For these array-valued fields that is a desirable tightening. Noted in the changelog.How tested
zarr.Arraymonkey-patches) and this branch, hdmf-zarr's zarr-v2-backward-compat read suite goes from 3 failed + 57 errors to 61 passed.Checklist
CHANGELOG.mdwith your changes?🤖 Generated with Claude Code