Fix NWBData shadowing the data attribute it inherits from Data - #2233
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #2233 +/- ##
==========================================
- Coverage 96.25% 96.22% -0.04%
==========================================
Files 30 30
Lines 3018 2993 -25
Branches 438 433 -5
==========================================
- Hits 2905 2880 -25
Misses 64 64
Partials 49 49
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:
|
|
Good catch @h-mayorquin ! I think this is ultimately due to an incomplete refactor when HDMF was extracted out of PyNWB and Could you also please simplify the changelog entry? The first sentence is sufficient. |
# Conflicts: # CHANGELOG.md
|
Yes. I modified the changelog as requested. It was the product of a verbose model in the top of a verbose person. Thanks for the review. |
|
Thanks @h-mayorquin . What do you think about removing all contents of |
__getitem__, append and extend all duplicated hdmf's Data with no added behavior, so hdmf now owns them.
|
Should be done. |
Motivation
I found this while trying to get neuroconv's default chunking and gzip compression to apply to
GrayscaleImagedatasets, and discovering that it silently did nothing.NWBDatare-declaresself.__datain its__init__and overrides thedataproperty to read it, which shadows the storage it inherits fromhdmf.container.Data. The inheritedset_data_iowrites the parent's attribute while.datareads the child's, so theDataIOwrapping is applied and then never seen again, and the dataset is written uncompressed with nothing warning you. This affects everyNWBDatasubclass, soScratchData,ImageReferences,ExternalImageand the image types, and the same shadow leavestransform,append, andextendoperating on a different attribute than the parent thinks it is holding.The fix is to let the parent own the storage. The private attribute and the
dataproperty go,__len__was a duplicate of hdmf's so it goes with them, andappendandextendbecome a type guard that delegates tosuper(), which keeps the existing error message for scalar data.Two behavior changes worth a reviewer's attention.
Data.__init__runscoerce_pandas_databefore storing whileNWBDatastashed the raw argument, so.datanow returns the coerced value, meaning apandas.Seriespassed asdatareads back as thendarraythat was always the thing actually written to the file. And becauseappendandextendnow go through hdmf'sappend_dataandextend_data, appending an array to ndarray-backed data concatenates instead of raisingValueError: all the input arrays must have same number of dimensions. That is the reproduction in #727, which this improves but does not close, since the list and ndarray cases still diverge. The existing test suite passes without modification.How to test the behavior?
Checklist
ruff check . && codespellfrom the source directory.