diff --git a/CHANGELOG b/CHANGELOG index 87642f85..c49000a3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,5 @@ 0.54.3 + - enh: more caching of event size and shape for HDF5 format - enh: faster computation of contour length for DCOR format - fix: implement `__contains__` for DCOR logs and tables - enh: use dcserv version 2 in DCOR format (fast S3 access) diff --git a/dclab/rtdc_dataset/fmt_hdf5/events.py b/dclab/rtdc_dataset/fmt_hdf5/events.py index bf2cbf86..e98df69e 100644 --- a/dclab/rtdc_dataset/fmt_hdf5/events.py +++ b/dclab/rtdc_dataset/fmt_hdf5/events.py @@ -38,7 +38,6 @@ def __iter__(self): def __len__(self): if self._length is None: - assert False # computing the length of an H5Group is slow self._length = len(self.h5group) return self._length @@ -207,6 +206,8 @@ def shape(self): class H5TraceEvent: def __init__(self, h5group): self.h5group = h5group + self._num_traces = None + self._shape = None def __getitem__(self, idx): return self.h5group[idx] @@ -215,7 +216,9 @@ def __contains__(self, item): return item in self.h5group def __len__(self): - return len(self.h5group) + if self._num_traces is None: + self._num_traces = len(self.h5group) + return self._num_traces def __iter__(self): for key in sorted(self.h5group.keys()): @@ -226,5 +229,8 @@ def keys(self): @property def shape(self): - atrace = list(self.h5group.keys())[0] - return tuple([len(self.h5group)] + list(self.h5group[atrace].shape)) + if self._shape is None: + atrace = list(self.h5group.keys())[0] + self._shape = tuple([len(self)] + list(self.h5group[atrace].shape)) + return self._shape +