Repository navigation
Fix reading a Units table whose columns are links - #2274
Open
monsterlag wants to merge 1 commit into
Open
monsterlag wants to merge 1 commit into
monsterlag wants to merge 1 commit into
Conversation
UnitsMap read attributes directly from the column builders, which fails with AttributeError when a column is a LinkBuilder, e.g., in a file written from a shallow copy made with NWBFile.copy(). Follow the link to the target builder first. Fix NeurodataWithoutBorders#1223
This branch has not been deployed
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.
Note
AI-generated, not reviewed by a human. This pull request was written by an AI coding agent and then checked by a separate AI review agent, which re-ran the tests described below. No human has reviewed the code. It is submitted by @monsterlag, who runs these agents. If that does not fit how you want to receive contributions, please feel free to close it.
Motivation
Fix #1223
Reading a file that was written from a shallow copy (
NWBFile.copy()) of a file with aUnitstable fails. In the copy, theUnitsgroup is new but its columns (spike_times,waveform_mean, ...) are links back to the original file, so the builders thatUnitsMapgets for them areLinkBuilders.UnitsMap.resolution_cargandUnitsMap._get_waveform_statread.attributesdirectly from those builders and fail with:The script in #1223 still reproduces this on current
dev(with HDMF 6.2.0).This PR adds a small
UnitsMap._get_column_builderhelper that follows the link to the target builder when a column is aLinkBuilder, the same wayTimeIntervalsMap.columns_cargalready handles a linkedtimeseriescolumn (#1863), and uses it in both places.resolution,waveform_rate,waveform_unit, andwaveform_time_before_peak_in_msare now read from the linked columns.How to test the behavior?
tests/integration/hdf5/test_file_copy.py::TestFileCopy::test_copy_file_link_units_columnswrites a file with aUnitstable that hasresolution,waveform_rate, andwaveform_unitset, writes a shallow copy of it, reads the copy, and checks those values and the spike times.Without the fix, the new test fails with
AttributeError: 'LinkBuilder' object has no attribute 'attributes'raised fromsrc/pynwb/io/misc.py. With the fix:python -m pytest tests/integration/hdf5/test_file_copy.py tests/integration/hdf5/test_misc.py tests/unit/test_misc.py: 75 passedpython -m pytest tests/unit tests/integration: 835 passed, 19 skippedruff check .andcodespell: cleanChecklist
ruff check . && codespellfrom the source directory.