From a5f543679bae5b47b7da70289122e6433e910c8b Mon Sep 17 00:00:00 2001 From: bendichter Date: Sun, 10 Mar 2019 15:41:46 -0400 Subject: [PATCH 1/2] fix slice indexing of DynamicTableRegion and add test --- src/pynwb/core.py | 10 +++------- tests/unit/pynwb_tests/test_core.py | 5 +++-- 2 files changed, 6 insertions(+), 9 deletions(-) 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..f381e0424 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]] + assert fetch_ids == [1, 2, 2] def test_nd_array_to_df(self): data = np.array([[1, 1, 1], [2, 2, 2], [3, 3, 3]]) From f49525457fa966665518a71b31136a61b78a39ec Mon Sep 17 00:00:00 2001 From: bendichter Date: Wed, 13 Mar 2019 12:26:59 -0400 Subject: [PATCH 2/2] change equality test to assertEqual --- tests/unit/pynwb_tests/test_core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/pynwb_tests/test_core.py b/tests/unit/pynwb_tests/test_core.py index f381e0424..a61f444d6 100644 --- a/tests/unit/pynwb_tests/test_core.py +++ b/tests/unit/pynwb_tests/test_core.py @@ -208,7 +208,7 @@ def test_indexed_dynamic_table_region(self): dynamic_table_region = DynamicTableRegion('dtr', [0, 1, 1], 'desc', table=table) fetch_ids = [x[1] for x in dynamic_table_region[:3]] - assert fetch_ids == [1, 2, 2] + 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]])