From 1c8735b6a10ac45e72b4f434484638011565fa42 Mon Sep 17 00:00:00 2001 From: michaellans Date: Fri, 31 Jul 2026 16:19:54 -0700 Subject: [PATCH 1/5] raise error at end of select_env if vars are nan --- src/badger/gui/mini/pages/routine_page.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/badger/gui/mini/pages/routine_page.py b/src/badger/gui/mini/pages/routine_page.py index 4bed3b91..212ae320 100644 --- a/src/badger/gui/mini/pages/routine_page.py +++ b/src/badger/gui/mini/pages/routine_page.py @@ -8,6 +8,7 @@ an existing Routine back into the form. """ +import math from typing import Any import warnings import traceback @@ -1184,6 +1185,19 @@ def select_env(self, i: int): # Update the docs self.window_env_docs.update_docs(env.name, "environment") + self.check_for_nan_vars() + + def check_for_nan_vars(self): + current_values = self.env_box.var_table.current_values + nan_value_keys = [ + key for key in current_values if math.isnan(current_values[key]) + ] + if len(nan_value_keys): + raise BadgerEnvVarError( + "Failed to connect or get values for the following variables:\n" + + f"{nan_value_keys}" + ) + def get_init_table_header(self): table = self.env_box.init_table header_list = [] From 543f7dd64cf664dc7bfceca6e8e10f4f69988d3b Mon Sep 17 00:00:00 2001 From: michaellans Date: Mon, 3 Aug 2026 09:39:02 -0700 Subject: [PATCH 2/5] check value type before isnan --- src/badger/gui/mini/pages/routine_page.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/badger/gui/mini/pages/routine_page.py b/src/badger/gui/mini/pages/routine_page.py index 212ae320..304f9cc4 100644 --- a/src/badger/gui/mini/pages/routine_page.py +++ b/src/badger/gui/mini/pages/routine_page.py @@ -8,7 +8,6 @@ an existing Routine back into the form. """ -import math from typing import Any import warnings import traceback @@ -1190,11 +1189,13 @@ def select_env(self, i: int): def check_for_nan_vars(self): current_values = self.env_box.var_table.current_values nan_value_keys = [ - key for key in current_values if math.isnan(current_values[key]) + key + for key, value in current_values.items() + if isinstance(value, (float, np.floating)) and np.isnan(value) ] if len(nan_value_keys): raise BadgerEnvVarError( - "Failed to connect or get values for the following variables:\n" + "Failed to get values for the following variables:\n" + f"{nan_value_keys}" ) From 5f977659a91b1f0ad8adb648b75942a08c1b6e7f Mon Sep 17 00:00:00 2001 From: michaellans Date: Mon, 3 Aug 2026 09:45:05 -0700 Subject: [PATCH 3/5] minor formatting --- src/badger/gui/mini/pages/routine_page.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/badger/gui/mini/pages/routine_page.py b/src/badger/gui/mini/pages/routine_page.py index 304f9cc4..323ec6aa 100644 --- a/src/badger/gui/mini/pages/routine_page.py +++ b/src/badger/gui/mini/pages/routine_page.py @@ -1186,7 +1186,8 @@ def select_env(self, i: int): self.check_for_nan_vars() - def check_for_nan_vars(self): + def check_for_nan_vars(self) -> None: + """Check whether any var_table values are NaN and raise error to notify user""" current_values = self.env_box.var_table.current_values nan_value_keys = [ key @@ -1195,8 +1196,7 @@ def check_for_nan_vars(self): ] if len(nan_value_keys): raise BadgerEnvVarError( - "Failed to get values for the following variables:\n" - + f"{nan_value_keys}" + f"Failed to get values for the following variables:\n{nan_value_keys}" ) def get_init_table_header(self): From 9f2bfda2b7046b19207a5fdba768de7f9200443f Mon Sep 17 00:00:00 2001 From: michaellans Date: Mon, 3 Aug 2026 18:21:56 -0700 Subject: [PATCH 4/5] switched to QMessageBox warning from BadgerEnvVarError --- src/badger/gui/mini/pages/routine_page.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/badger/gui/mini/pages/routine_page.py b/src/badger/gui/mini/pages/routine_page.py index 323ec6aa..412dd456 100644 --- a/src/badger/gui/mini/pages/routine_page.py +++ b/src/badger/gui/mini/pages/routine_page.py @@ -1194,9 +1194,12 @@ def check_for_nan_vars(self) -> None: for key, value in current_values.items() if isinstance(value, (float, np.floating)) and np.isnan(value) ] - if len(nan_value_keys): - raise BadgerEnvVarError( - f"Failed to get values for the following variables:\n{nan_value_keys}" + if nan_value_keys: + nan_vars = "\n".join(f" - {key}" for key in nan_value_keys) + QMessageBox.warning( + self, + "Unable to connect to some variables", + f"Failed to get values for the following variables:\n{nan_vars}", ) def get_init_table_header(self): From d975e6dc1dbb95bf34a2fb58d5885cb4081458c5 Mon Sep 17 00:00:00 2001 From: michaellans Date: Mon, 3 Aug 2026 18:51:39 -0700 Subject: [PATCH 5/5] split out get_nan_vars into env_cbox method --- src/badger/gui/mini/components/env_cbox.py | 10 ++++++++++ src/badger/gui/mini/pages/routine_page.py | 11 +++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/badger/gui/mini/components/env_cbox.py b/src/badger/gui/mini/components/env_cbox.py index 29327a0a..8074ba77 100644 --- a/src/badger/gui/mini/components/env_cbox.py +++ b/src/badger/gui/mini/components/env_cbox.py @@ -27,6 +27,7 @@ QLabel, ) from PyQt5.QtCore import QRegExp, pyqtSignal +import numpy as np from badger.gui.components.obs_table import ObservableTable from badger.settings import init_settings from pydantic_core import ValidationError @@ -659,6 +660,15 @@ def filter_var(self): self.var_table.update_variables(_variables, 1) + def get_nan_vars(self) -> list[str]: + """Return keys of var_table entries with NaN values""" + current_values = self.var_table.current_values + return [ + key + for key, value in current_values.items() + if isinstance(value, (float, np.floating)) and np.isnan(value) + ] + def toggle_obj_show_mode(self, _): self.obj_table.update_show_selected_only(self.check_only_obj.isChecked()) diff --git a/src/badger/gui/mini/pages/routine_page.py b/src/badger/gui/mini/pages/routine_page.py index 412dd456..889ae4af 100644 --- a/src/badger/gui/mini/pages/routine_page.py +++ b/src/badger/gui/mini/pages/routine_page.py @@ -1187,18 +1187,13 @@ def select_env(self, i: int): self.check_for_nan_vars() def check_for_nan_vars(self) -> None: - """Check whether any var_table values are NaN and raise error to notify user""" - current_values = self.env_box.var_table.current_values - nan_value_keys = [ - key - for key, value in current_values.items() - if isinstance(value, (float, np.floating)) and np.isnan(value) - ] + """Show a warning popup to notify user if any var_table values are NaN""" + nan_value_keys = self.env_box.get_nan_vars() if nan_value_keys: nan_vars = "\n".join(f" - {key}" for key in nan_value_keys) QMessageBox.warning( self, - "Unable to connect to some variables", + "Variables with invalid values", f"Failed to get values for the following variables:\n{nan_vars}", )