Skip to content

Commit

Permalink
Show waring when the chunk_number is not needed (#883)
Browse files Browse the repository at this point in the history
* Show waring when the `chunk_number` is not needed

* Minor debug
  • Loading branch information
dachengx authored Aug 26, 2024
1 parent 1e42cda commit 8e189a7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
21 changes: 16 additions & 5 deletions strax/context.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import time
import logging
import warnings
import fnmatch
import itertools
import json
Expand Down Expand Up @@ -370,7 +369,7 @@ def register(self, plugin_class):
if old_plugin == currently_registered:
# Must be equal here, because we are only looking for the remanants which were
# not overwritten above.
warnings.warn(
self.log.warning(
"Provides of multi-output plugins overlap, deregister old plugins"
f" {old_plugin}."
)
Expand Down Expand Up @@ -1089,8 +1088,6 @@ def get_components(
if len(t) == 1:
raise ValueError(f"Plugin names must be more than one letter, not {t}")

plugins = self._get_plugins(targets, run_id, chunk_number=chunk_number)

_is_superrun = run_id.startswith("_")
if len(targets) > 1 and _combining_subruns:
raise ValueError("Combining subruns is only supported for a single target")
Expand All @@ -1099,6 +1096,20 @@ def get_components(
if not _is_superrun and _combining_subruns:
raise ValueError("Combining subruns is only supported for superruns.")

sources = set().union(
*[s for s in (self.get_source(run_id, target) for target in targets) if s is not None]
)
if chunk_number is not None:
chunk_number_keys = set(chunk_number.keys())
if not chunk_number_keys <= sources:
self.log.warning(
f"Chunk number is specified for dependencies {chunk_number_keys} "
f"but {targets} are made from stored dependencies {sources}. "
"So some values in chunk_number will be ignored."
)

plugins = self._get_plugins(targets, run_id, chunk_number=chunk_number)

allow_superruns = [plugins[target_i].allow_superrun for target_i in targets]
if _is_superrun and sum(allow_superruns) not in [0, len(targets)]:
raise ValueError(
Expand Down Expand Up @@ -2209,7 +2220,7 @@ def is_stored(self, run_id, target, detailed=False, chunk_number=None, **kwargs)
save_when = save_when[target]

if save_when < strax.SaveWhen.ALWAYS and detailed:
warnings.warn(
self.log.warning(
f"{target} is not set to always be saved. "
"This is probably because it can be trivially made from other data. "
f"{target} depends on {plugin.depends_on}. Check if these are stored."
Expand Down
2 changes: 1 addition & 1 deletion tests/test_superruns.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def test_storing_with_second_sf(self):
def test_superrun_chunk_number(self):
"""Test that superrun does not work with chunk_number."""
with self.assertRaises(ValueError):
self.context.get_array(self.superrun_name, "peaks", chunk_number=[0])
self.context.get_array(self.superrun_name, "peaks", chunk_number={"raw_records": [0]})

def test_bare_combining_subruns(self):
"""Test that _combining_subruns does not work with non-superrun."""
Expand Down

0 comments on commit 8e189a7

Please sign in to comment.