Fix indexing an empty DynamicTableRegion selection in memory - #1549
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #1549 +/- ##
=======================================
Coverage 93.22% 93.22%
=======================================
Files 41 41
Lines 10221 10221
Branches 2115 2115
=======================================
Hits 9529 9529
Misses 415 415
Partials 277 277 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
VectorIndex.get inspects arg[0] to detect a boolean mask before the len(indices) > 0 guard that handles the empty case, so an empty list or array raised IndexError. This surfaces through DynamicTableRegion.get when a region row references no target rows and the target table has a ragged column. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Separate the paragraphs of the DynamicTableRegion.get comment block, and state what the with_array_columns fixture is rather than contrasting it with the list-backed fixture. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
|
Thanks @h-mayorquin ! I added an extra check to cover the case where the DynamicTableRegion points to a ragged column and this error was raised: |
rly
approved these changes
Jul 30, 2026
rly
approved these changes
Jul 30, 2026
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
Selecting a zero-length region from a
DynamicTableRegionraisedIndexError: arrays used as indices must be of integer (or boolean) typewhen the target table's columns held their data as numpy arrays. This happens for an empty slice and, more commonly, for a ragged region row that references no target rows, which is the shape produced when rows are appended to a table whoseDynamicTableRegioncolumn has no targets for them.DynamicTableRegion.gettakesnp.uniqueof the selected row indices, andnp.uniqueof an empty selection returns afloat64array, which numpy rejects as an index. A column whose data is a list takes a different branch inData.get, indexing elementwise, and tolerates the float array, which is why the existingTestDynamicTableRegionsuite, whose fixture is built from lists, stayed green.The same selection works for files on disk, because the indices come back from HDF5 already integer-typed, so the container behaves differently in memory than it did after a round trip. I think it should work for both cases. I cast the unique row indices to an integer dtype rather than returning early on an empty selection, because region data are row indices: the cast is a no-op when the selection is non-empty, and it fixes the class of problem (a non-integer index array) rather than the one input that produces it.
I found this downstream in AllenNeuralDynamics/aind-ephys-pipeline#121, reported by @alejoe91 @CodyCBakerPhD, where units from a second probe are appended to an NWB units table that already has an
electrodesregion column. Those units are written with an empty region, the file writes and reads back correctly, and only inspecting the in-memoryNWBFilebefore writing raised.How to test the behavior?
Checklist
CHANGELOG.mdwith your changes?