def _get_object_fields(self): """# fetch list of field names that compose the object list.""" object_fields = {} for set_name in self._sets: data = self.hdf5_file['/{}/object_fields'.format(set_name)].value object_fields[set_name] = tuple(convert_ascii_to_str(data)) return object_fields
def get(self, index=None, convert_to_str=False): """Retrieves data of the field from the dataset's hdf5 metadata file. This method retrieves the i'th data from the hdf5 file. Also, it is possible to retrieve multiple values by inserting a list/tuple of number values as indexes. Parameters ---------- index : int/list/tuple, optional Index number of he field. If it is a list, returns the data for all the value indexes of that list. convert_to_str : bool, optional Convert the output data into a string. Warning: output must be of type np.uint8 Returns ------- np.ndarray/list/str Numpy array containing the field's data. If convert_to_str is set to True, it returns a string or list of strings. Note ---- When using lists/tuples of indexes, this method sorts the list and removes duplicate values. This is because the h5py api requires the indexing elements to be in increasing order when retrieving data. """ if index is None: data = self._get_all_idx() else: data = self._get_range_idx(index) if convert_to_str: data = convert_ascii_to_str(data) return data
def test_convert_ascii_to_str__raises_error__empty_input(): with pytest.raises(AssertionError): convert_ascii_to_str([])
def _get_object_fields(self): object_fields_data = self.hdf5_group['object_fields'].value output = convert_ascii_to_str(object_fields_data) if type(output) == 'string': output = (output, ) return output
def test_convert_ascii_to_str_multiple_strings(sample, output): res = convert_ascii_to_str(np.array(sample, dtype=np.uint8)) assert(output == res)