Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn if user checks is_stored for plugin not always saved #796

Merged
merged 8 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion strax/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -1981,7 +1981,7 @@ def run_defaults(self, run_id):
self._run_defaults_cache[run_id] = defs
return defs

def is_stored(self, run_id, target, **kwargs):
def is_stored(self, run_id, target, detailed=True, **kwargs):
"""Return whether data type target has been saved for run_id through any of the registered
storage frontends.

Expand All @@ -2003,6 +2003,31 @@ def is_stored(self, run_id, target, **kwargs):
if self._is_stored_in_sf(run_id, target, sf):
return True
# None of the frontends has the data

# Before returning False, check if the data can be made trivially
plugin = self._plugin_class_registry[target]
save_when = plugin.save_when

# Mutli-target plugins provide a save_when per target
if isinstance(save_when, immutabledict):
save_when = save_when[target]

if save_when < strax.SaveWhen.ALWAYS and detailed:
msg = (
f"{target} is not set to always be saved. "
"This is probably because it can be trivially made from other data. "
)

try:
components = self.get_components(run_id, target)
targets_plugin_made_from = tuple(components.loaders.keys())
msg += f"{target} can be made from: {targets_plugin_made_from}."
except strax.DataNotAvailable as e:
# Warn that data cannot be made
msg += str(e)

warnings.warn(msg)

return False

def _check_forbidden(self):
Expand Down
16 changes: 8 additions & 8 deletions tests/test_superruns.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,17 +251,17 @@ def test_superrun_triggers_subrun_processing(self):

def test_superruns_and_save_when(self):
"""Tests if only the highest level for save_when.EXPLICIT plugins is stored."""
assert not self.context.is_stored(self.superrun_name, "peaks")
assert not self.context.is_stored(self.subrun_ids[0], "peaks")
assert not self.context.is_stored(self.subrun_ids[0], "peaks_extension")
assert not self.context.is_stored(self.superrun_name, "peaks_extension")
assert not self.context.is_stored(self.superrun_name, "peaks", detailed=False)
assert not self.context.is_stored(self.subrun_ids[0], "peaks", detailed=False)
assert not self.context.is_stored(self.subrun_ids[0], "peaks_extension", detailed=False)
assert not self.context.is_stored(self.superrun_name, "peaks_extension", detailed=False)
self.context._plugin_class_registry["peaks"].save_when = strax.SaveWhen.EXPLICIT

self.context.make(self.superrun_name, "peaks_extension", save=("peaks_extension",))
assert not self.context.is_stored(self.superrun_name, "peaks")
assert not self.context.is_stored(self.subrun_ids[0], "peaks")
assert self.context.is_stored(self.superrun_name, "peaks_extension")
assert self.context.is_stored(self.subrun_ids[0], "peaks_extension")
assert not self.context.is_stored(self.superrun_name, "peaks", detailed=False)
assert not self.context.is_stored(self.subrun_ids[0], "peaks", detailed=False)
assert self.context.is_stored(self.superrun_name, "peaks_extension", detailed=False)
assert self.context.is_stored(self.subrun_ids[0], "peaks_extension", detailed=False)

def test_storing_with_second_sf(self):
"""Tests if only superrun is written to new sf if subruns already exist in different sf."""
Expand Down