diff --git a/src/pynwb/core.py b/src/pynwb/core.py index d11e7e9bc..30f87b7dd 100644 --- a/src/pynwb/core.py +++ b/src/pynwb/core.py @@ -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) diff --git a/tests/unit/pynwb_tests/test_core.py b/tests/unit/pynwb_tests/test_core.py index 67989f809..a61f444d6 100644 --- a/tests/unit/pynwb_tests/test_core.py +++ b/tests/unit/pynwb_tests/test_core.py @@ -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]])