diff --git a/src/ert/config/design_matrix.py b/src/ert/config/design_matrix.py index 02f12c3e6ba..b1d9bb199a0 100644 --- a/src/ert/config/design_matrix.py +++ b/src/ert/config/design_matrix.py @@ -129,23 +129,26 @@ def read_design_matrix( # Read the parameter names (first row) as strings to prevent pandas from modifying them. # This ensures that duplicate or empty column names are preserved exactly as they appear in the Excel sheet. # By doing this, we can properly validate variable names, including detecting duplicates or missing names. - param_names = ( - pd.read_excel( + try: + param_names = ( + pd.read_excel( + self.xls_filename, + sheet_name=self.design_sheet, + nrows=1, + header=None, + dtype="string", + ) + .iloc[0] + .apply(lambda x: x.strip() if isinstance(x, str) else x) + ) + design_matrix_df = DesignMatrix._read_excel( self.xls_filename, - sheet_name=self.design_sheet, - nrows=1, + self.design_sheet, header=None, - dtype="string", + skiprows=1, ) - .iloc[0] - .apply(lambda x: x.strip() if isinstance(x, str) else x) - ) - design_matrix_df = DesignMatrix._read_excel( - self.xls_filename, - self.design_sheet, - header=None, - skiprows=1, - ) + except (ValueError, AttributeError) as exc: + raise ValueError(f"Error reading design matrix: {exc}") from exc design_matrix_df.columns = param_names.to_list() if "REAL" in design_matrix_df.columns: diff --git a/src/ert/gui/simulation/ensemble_experiment_panel.py b/src/ert/gui/simulation/ensemble_experiment_panel.py index 417f97c057c..9e4a023d486 100644 --- a/src/ert/gui/simulation/ensemble_experiment_panel.py +++ b/src/ert/gui/simulation/ensemble_experiment_panel.py @@ -85,25 +85,31 @@ def __init__( design_matrix = analysis_config.design_matrix if design_matrix is not None: + design_matrix_err: str = "" if design_matrix.design_matrix_df is None: - design_matrix.read_design_matrix() - - if design_matrix.active_realizations: - self._active_realizations_field.setText( - ActiveRange(design_matrix.active_realizations).rangestring + try: + design_matrix.read_design_matrix() + except (ValueError, AttributeError) as exc: + design_matrix_err = str(exc) + if design_matrix_err: + layout.addRow("Design Matrix", QLabel(design_matrix_err)) + else: + if design_matrix.active_realizations: + self._active_realizations_field.setText( + ActiveRange(design_matrix.active_realizations).rangestring + ) + show_dm_param_button = QPushButton("Show parameters") + show_dm_param_button.setObjectName("show-dm-parameters") + show_dm_param_button.setMinimumWidth(50) + + button_layout = QHBoxLayout() + button_layout.addWidget(show_dm_param_button) + button_layout.addStretch() # Add stretch to push the button to the left + + layout.addRow("Design Matrix", button_layout) + show_dm_param_button.clicked.connect( + lambda: self.on_show_dm_params_clicked(design_matrix) ) - show_dm_param_button = QPushButton("Show parameters") - show_dm_param_button.setObjectName("show-dm-parameters") - show_dm_param_button.setMinimumWidth(50) - - button_layout = QHBoxLayout() - button_layout.addWidget(show_dm_param_button) - button_layout.addStretch() # Add stretch to push the button to the left - - layout.addRow("Design Matrix", button_layout) - show_dm_param_button.clicked.connect( - lambda: self.on_show_dm_params_clicked(design_matrix) - ) self.setLayout(layout)