diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b0ac581b..89b20d757 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixed - Fixed copying of `TypeMap` and `TypeConfigurator`. Previously, the same global `TypeConfigurator` instance was used in all copies of a `TypeMap`. @rly [#1302](https://github.com/hdmf-dev/hdmf/pull/1302) - Fixed `get_data_shape` to use `Data.data.shape` instead of `Data.shape`, which may be overridden by subclasses. @rly [#1311](https://github.com/hdmf-dev/hdmf/pull/1311) +- Fixed a broken test and refactored `VectorIndex.get`. @rly, @mavaylon1 [#1293](https://github.com/hdmf-dev/hdmf/pull/1293) ### Added - Added a check for a compound datatype that is not defined in the schema or spec. This is currently not supported. @mavaylon1 [#1276](https://github.com/hdmf-dev/hdmf/pull/1276) diff --git a/src/hdmf/common/table.py b/src/hdmf/common/table.py index f4b2cd011..278ba9dbf 100644 --- a/src/hdmf/common/table.py +++ b/src/hdmf/common/table.py @@ -204,21 +204,8 @@ def get(self, arg, **kwargs): indices = arg ret = list() if len(indices) > 0: - # Note: len(indices) == 0 for test_to_hierarchical_dataframe_empty_tables. - # This is an edge case test for to_hierarchical_dataframe() on empty tables. - # When len(indices) == 0, ret is expected to be an empty list, defined above. - try: - data = self.target.get(slice(None), **kwargs) - except IndexError: - """ - Note: TODO: test_to_hierarchical_dataframe_indexed_dtr_on_last_level. - This is the old way to get the data and not an untested feature. - """ - for i in indices: - ret.append(self.__getitem_helper(i, **kwargs)) - - return ret - + # Load the entire target table at once to avoid multiple I/O calls + data = self.target.get(slice(None), **kwargs) slices = [self.__get_slice(i) for i in indices] if isinstance(data, pd.DataFrame): ret = [data.iloc[s] for s in slices] diff --git a/tests/unit/common/test_linkedtables.py b/tests/unit/common/test_linkedtables.py index 3c1c63170..d8d48e6b2 100644 --- a/tests/unit/common/test_linkedtables.py +++ b/tests/unit/common/test_linkedtables.py @@ -445,7 +445,7 @@ def test_to_hierarchical_dataframe_indexed_dtr_on_last_level(self): p1 = DynamicTable(name='parent_table', description='parent_table', columns=[VectorData(name='p1', description='p1', data=np.arange(3)), dtr_p1, vi_dtr_p1]) # Super-parent table - dtr_sp = DynamicTableRegion(name='sl1', description='sl1', data=np.arange(4), table=p1) + dtr_sp = DynamicTableRegion(name='sl1', description='sl1', data=np.arange(3), table=p1) vi_dtr_sp = VectorIndex(name='sl1_index', data=[1, 2, 3], target=dtr_sp) spt = DynamicTable(name='super_parent_table', description='super_parent_table', columns=[VectorData(name='sp1', description='sp1', data=np.arange(3)), dtr_sp, vi_dtr_sp])