diff --git a/strax/plugins/down_chunking_plugin.py b/strax/plugins/down_chunking_plugin.py index 3138d221..f732b19b 100644 --- a/strax/plugins/down_chunking_plugin.py +++ b/strax/plugins/down_chunking_plugin.py @@ -53,4 +53,5 @@ def _fix_output(self, result, start, end, superrun, subruns, _dtype=None): f"Plugin {self.__class__.__name__} should yield (dict of) " "strax.Chunk in compute method." ) + self._check_sorted(_result) yield self.superrun_transformation(_result, superrun, subruns) diff --git a/strax/plugins/plugin.py b/strax/plugins/plugin.py index 3a725637..0777f0ef 100644 --- a/strax/plugins/plugin.py +++ b/strax/plugins/plugin.py @@ -616,6 +616,18 @@ def _check_dtype(self, x, d=None): f"Delivered: {got}." ) + def _check_sorted(self, result): + # check the result is sorted in time + if self.multi_output: + for d in self.provides: + self._check_sorted(result[d]) + + if len(result.data) < 2: + return + + if np.diff(result.data["time"]).min() < 0: + raise ValueError(f"Plugin {self.__class__.__name__} did not return sorted time!") + @staticmethod def _check_subruns_uniqueness(kwargs, subrunses): """Check if the subruns of the all inputs are the same.""" @@ -788,6 +800,7 @@ def _fix_output(self, result, start, end, superrun, subruns, _dtype=None): f"{self.__class__.__name__} returned a Chunk with data_type " f"{result.data_type} instead of {_dtype}." ) + self._check_sorted(result) return self.superrun_transformation(result, superrun, subruns) def chunk(self, *, start, end, data, data_type=None, run_id=None):