From 8b8cff6ca29ea6bcd4dacc08d6cfff32505f1e59 Mon Sep 17 00:00:00 2001 From: dachengx Date: Mon, 22 Sep 2025 08:41:42 -0500 Subject: [PATCH 1/2] Check whether the result of plugin is sorted --- strax/plugins/down_chunking_plugin.py | 1 + strax/plugins/plugin.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/strax/plugins/down_chunking_plugin.py b/strax/plugins/down_chunking_plugin.py index 3138d2215..f732b19bd 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 3a725637b..d57d419ab 100644 --- a/strax/plugins/plugin.py +++ b/strax/plugins/plugin.py @@ -616,6 +616,22 @@ 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: + if not isinstance(result, dict): + raise ValueError( + f"{self.__class__.__name__} is multi-output and should " + "provide a dict output." + ) + return {d: self._check_sorted(result[d]) for d in self.provides} + + 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 +804,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): From fa0cfb5e5705d04751c6c242b16e6342cd9d69bf Mon Sep 17 00:00:00 2001 From: dachengx Date: Mon, 22 Sep 2025 09:30:19 -0500 Subject: [PATCH 2/2] Debug --- strax/plugins/plugin.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/strax/plugins/plugin.py b/strax/plugins/plugin.py index d57d419ab..0777f0ef6 100644 --- a/strax/plugins/plugin.py +++ b/strax/plugins/plugin.py @@ -619,12 +619,8 @@ def _check_dtype(self, x, d=None): def _check_sorted(self, result): # check the result is sorted in time if self.multi_output: - if not isinstance(result, dict): - raise ValueError( - f"{self.__class__.__name__} is multi-output and should " - "provide a dict output." - ) - return {d: self._check_sorted(result[d]) for d in self.provides} + for d in self.provides: + self._check_sorted(result[d]) if len(result.data) < 2: return