Commit 36f20287 authored by Gaetano Scandariato's avatar Gaetano Scandariato
Browse files

fix(sampling): resolve B904 exception chaining warnings

Explicitly chain or suppress exceptions using raise ... from err / None:
- utils.py: raise ValueError from e
- detrending.py: raise ValueError from e
- data_loader.py: raise ValueError from e
- priors.py: raise ValueError from None (clean user message)
- sampling_logging.py: raise ValueError from None (clean user message)
parent d7429366
Loading
Loading
Loading
Loading
Loading
+1 −1
Changes for PyAETNA/sampling/config/parser/detrending.py: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -236,7 +236,7 @@ def parse_fourier(
            except Exception as e:
                raise ValueError(
                    f"Fourier series '{fourier_name}': Invalid 'period' expression '{period}': {e!s}"
                )
                ) from e
        else:
            period = float(period)

+1 −1
Changes for PyAETNA/sampling/config/priors.py: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@ def _parse_prior_string(prior_spec):
            except Exception:
                raise ValueError(
                    f"Unknown prior format: '{prior_spec}'. Use [dist_name, param1, param2, ...] format or a valid math expression."
                )
                ) from None

    # Handle YAML list format: [dist_name, param1, param2, ...]
    if isinstance(prior_spec, list):
+1 −1
Changes for PyAETNA/sampling/engine/data_loader.py: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -292,7 +292,7 @@ def load_data_and_config(
                    raise ValueError(
                        f"Failed to compute component count for SpectralMixture "
                        f"kernel in section '{inst_id}': {e}"
                    )
                    ) from e

    _log_config_summary(param_config, plModel, instrument_names, log_func)

+1 −1
Changes for PyAETNA/sampling/engine/sampling_logging.py: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -649,7 +649,7 @@ def _log_config_summary(param_config, plModel, instrument_names, logger):
                    raise ValueError(
                        "Internal error: SpectralMixture component count not found in configuration. "
                        "This indicates a failure in the configuration validation process."
                    )
                    ) from None

    lines.append("=" * 90)

+1 −1
Changes for PyAETNA/sampling/utils.py: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -259,4 +259,4 @@ def _safe_eval_math(expr):

        return float(_eval(node))
    except Exception as e:
        raise ValueError(f"Cannot evaluate expression '{expr}': {e}")
        raise ValueError(f"Cannot evaluate expression '{expr}': {e}") from e