Skip to content

Commit 85eccb6

Browse files
authored
Merge pull request #843 from NeurodataWithoutBorders/fix/dyn_tab_ref_indexing
fix slice indexing of DynamicTableRegion and add test
2 parents 6bb2a01 + f495254 commit 85eccb6

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

src/pynwb/core.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,11 +1361,7 @@ def __getitem__(self, key):
13611361
arg1 = key[0]
13621362
arg2 = key[1]
13631363
return self.table[self.data[arg1], arg2]
1364-
elif isinstance(key, slice):
1365-
data = np.arange(*key.indices(len(self.table)))
1366-
return DynamicTableRegion(name=self.name, data=data, description=self.description, table=self.table)
1364+
elif isinstance(key, (int, slice)):
1365+
return self.table[self.data[key]]
13671366
else:
1368-
if isinstance(key, int):
1369-
return self.table[self.data[key]]
1370-
else:
1371-
raise ValueError("unrecognized argument: '%s'" % key)
1367+
raise ValueError("unrecognized argument: '%s'" % key)

tests/unit/pynwb_tests/test_core.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,9 @@ def test_extra_columns(self):
206206
def test_indexed_dynamic_table_region(self):
207207
table = self.with_columns_and_data()
208208

209-
dynamic_table_region = DynamicTableRegion('dtr', [0, 1], 'desc', table=table)
210-
assert dynamic_table_region[slice(0, 1)]
209+
dynamic_table_region = DynamicTableRegion('dtr', [0, 1, 1], 'desc', table=table)
210+
fetch_ids = [x[1] for x in dynamic_table_region[:3]]
211+
self.assertEqual(fetch_ids, [1, 2, 2])
211212

212213
def test_nd_array_to_df(self):
213214
data = np.array([[1, 1, 1], [2, 2, 2], [3, 3, 3]])

0 commit comments

Comments
 (0)