Nilesh Patra pushed to branch upstream at Debian Med / hdmf
Commits: 859451d4 by Nilesh Patra at 2021-06-22T08:49:37+05:30 New upstream version 2.5.8 - - - - - 5 changed files: - PKG-INFO - src/hdmf.egg-info/PKG-INFO - src/hdmf/_version.py - src/hdmf/common/table.py - tests/unit/common/test_table.py Changes: ===================================== PKG-INFO ===================================== @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: hdmf -Version: 2.5.7 +Version: 2.5.8 Summary: A package for standardizing hierarchical object data Home-page: https://github.com/hdmf-dev/hdmf Author: Andrew Tritt ===================================== src/hdmf.egg-info/PKG-INFO ===================================== @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: hdmf -Version: 2.5.7 +Version: 2.5.8 Summary: A package for standardizing hierarchical object data Home-page: https://github.com/hdmf-dev/hdmf Author: Andrew Tritt ===================================== src/hdmf/_version.py ===================================== @@ -8,11 +8,11 @@ import json version_json = ''' { - "date": "2021-06-04T18:02:01-0700", + "date": "2021-06-16T13:54:41-0700", "dirty": false, "error": null, - "full-revisionid": "1b084d56ca66d73ed05fd83b5657c0824f4b72c5", - "version": "2.5.7" + "full-revisionid": "929ec93232bfa1069c764abc7b3b280ab0fc0c1e", + "version": "2.5.8" } ''' # END VERSION_JSON ===================================== src/hdmf/common/table.py ===================================== @@ -107,28 +107,33 @@ class VectorIndex(VectorData): def __check_precision(self, idx): """ - Check precision of current dataset and, if - necessary, adjust precision to accommodate new value. + Check precision of current dataset and, if necessary, adjust precision to accommodate new value. Returns: unsigned integer encoding of idx """ if idx > self.__maxval: - nbits = (np.log2(self.__maxval + 1) * 2) + while idx > self.__maxval: + nbits = (np.log2(self.__maxval + 1) * 2) # 8->16, 16->32, 32->64 + if nbits == 128: # pragma: no cover + msg = ('Cannot store more than 18446744073709551615 elements in a VectorData. Largest dtype ' + 'allowed for VectorIndex is uint64.') + raise ValueError(msg) + self.__maxval = 2 ** nbits - 1 self.__uint = np.dtype('uint%d' % nbits).type - self.__maxval = 2 ** nbits - 1 self.__adjust_precision(self.__uint) return self.__uint(idx) def __adjust_precision(self, uint): """ - Adjust precision of data to specificied unsigned integer precision + Adjust precision of data to specificied unsigned integer precision. """ if isinstance(self.data, list): for i in range(len(self.data)): self.data[i] = uint(self.data[i]) elif isinstance(self.data, np.ndarray): - self._VectorIndex__data = self.data.astype(uint) + # use self._Data__data to work around restriction on resetting self.data + self._Data__data = self.data.astype(uint) else: raise ValueError("cannot adjust precision of type %s to %s", (type(self.data), uint)) ===================================== tests/unit/common/test_table.py ===================================== @@ -1838,3 +1838,66 @@ class TestDTRReferences(TestCase): 'y': [read_group1, read_group2]}, index=pd.Index(data=[102, 103], name='id')) pd.testing.assert_frame_equal(ret, expected) + + +class TestVectorIndexDtype(TestCase): + + def set_up_array_index(self): + data = VectorData(name='data', description='desc') + index = VectorIndex(name='index', data=np.array([]), target=data) + return index + + def set_up_list_index(self): + data = VectorData(name='data', description='desc') + index = VectorIndex(name='index', data=[], target=data) + return index + + def test_array_inc_precision(self): + index = self.set_up_array_index() + index.add_vector(np.empty((255, ))) + self.assertEqual(index.data[0], 255) + self.assertEqual(index.data.dtype, np.uint8) + + def test_array_inc_precision_1step(self): + index = self.set_up_array_index() + index.add_vector(np.empty((65535, ))) + self.assertEqual(index.data[0], 65535) + self.assertEqual(index.data.dtype, np.uint16) + + def test_array_inc_precision_2steps(self): + index = self.set_up_array_index() + index.add_vector(np.empty((65536, ))) + self.assertEqual(index.data[0], 65536) + self.assertEqual(index.data.dtype, np.uint32) + + def test_array_prev_data_inc_precision_2steps(self): + index = self.set_up_array_index() + index.add_vector(np.empty((255, ))) # dtype is still uint8 + index.add_vector(np.empty((65536, ))) + self.assertEqual(index.data[0], 255) # make sure the 255 is upgraded + self.assertEqual(index.data.dtype, np.uint32) + + def test_list_inc_precision(self): + index = self.set_up_list_index() + index.add_vector(list(range(255))) + self.assertEqual(index.data[0], 255) + self.assertEqual(type(index.data[0]), np.uint8) + + def test_list_inc_precision_1step(self): + index = self.set_up_list_index() + index.add_vector(list(range(65535))) + self.assertEqual(index.data[0], 65535) + self.assertEqual(type(index.data[0]), np.uint16) + + def test_list_inc_precision_2steps(self): + index = self.set_up_list_index() + index.add_vector(list(range(65536))) + self.assertEqual(index.data[0], 65536) + self.assertEqual(type(index.data[0]), np.uint32) + + def test_list_prev_data_inc_precision_2steps(self): + index = self.set_up_list_index() + index.add_vector(list(range(255))) + index.add_vector(list(range(65536 - 255))) + self.assertEqual(index.data[0], 255) # make sure the 255 is upgraded + self.assertEqual(type(index.data[0]), np.uint32) View it on GitLab: https://salsa.debian.org/med-team/hdmf/-/commit/859451d4bedf5cfccf582aaabe86d2eca80b6fde -- View it on GitLab: https://salsa.debian.org/med-team/hdmf/-/commit/859451d4bedf5cfccf582aaabe86d2eca80b6fde You're receiving this email because of your account on salsa.debian.org.
_______________________________________________ debian-med-commit mailing list [email protected] https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/debian-med-commit
