Skip to content

Commit

Permalink
Merge pull request #843 from NeurodataWithoutBorders/fix/dyn_tab_ref_…
Browse files Browse the repository at this point in the history
…indexing

fix slice indexing of DynamicTableRegion and add test
  • Loading branch information
bendichter authored Mar 13, 2019
2 parents 6bb2a01 + f495254 commit 85eccb6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
10 changes: 3 additions & 7 deletions src/pynwb/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1361,11 +1361,7 @@ def __getitem__(self, key):
arg1 = key[0]
arg2 = key[1]
return self.table[self.data[arg1], arg2]
elif isinstance(key, slice):
data = np.arange(*key.indices(len(self.table)))
return DynamicTableRegion(name=self.name, data=data, description=self.description, table=self.table)
elif isinstance(key, (int, slice)):
return self.table[self.data[key]]
else:
if isinstance(key, int):
return self.table[self.data[key]]
else:
raise ValueError("unrecognized argument: '%s'" % key)
raise ValueError("unrecognized argument: '%s'" % key)
5 changes: 3 additions & 2 deletions tests/unit/pynwb_tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,9 @@ def test_extra_columns(self):
def test_indexed_dynamic_table_region(self):
table = self.with_columns_and_data()

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

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

0 comments on commit 85eccb6

Please sign in to comment.