From 698f5a6833337d0f263b60ca1e776627368b1e30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20S=C3=B8rli?= <81353974+arneso-ssb@users.noreply.github.com> Date: Thu, 19 Sep 2024 13:39:38 +0200 Subject: [PATCH] Fix darglint errors --- src/model_solver/model_solver.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/model_solver/model_solver.py b/src/model_solver/model_solver.py index 3f0f9b2..581c0dc 100644 --- a/src/model_solver/model_solver.py +++ b/src/model_solver/model_solver.py @@ -627,9 +627,9 @@ def switch_endo_vars( in the list of endogenous variables. """ if all(x in self.endo_vars for x in old_endo_vars) is False: - raise RuntimeError("all variables in old_endo_vars are not endogenous") + raise ValueError("all variables in old_endo_vars are not endogenous") if any(x in self.endo_vars for x in new_endo_vars): - raise RuntimeError("some variables in new_endo_vars are endogenous") + raise ValueError("some variables in new_endo_vars are endogenous") print("Analyzing model") self._endo_vars = ( @@ -663,6 +663,9 @@ def find_endo_var(self, endo_var: str, noisy: bool = False) -> int | None: Returns: The block number of the block that solves the specified endogenous variable. Returns `None` if the endogenous variable is not found in any block. + + Raises: + IndexError: If `endo_var` is not endogenous in model. """ block = [key for key, val in self._blocks.items() if endo_var.lower() in val[0]] if block: @@ -765,6 +768,8 @@ def show_block(self, i: int) -> None: Args: i: The index of the block to display. + Raises: + IndexError: If block `i` is not in model. Example: @@ -1320,6 +1325,9 @@ def trace_to_exog_vals( Returns: A `pd.Series` of exogenous values, or `None`. + Raises: + RuntimeError: If no solution is found. + Example: .. code-block:: python @@ -1388,6 +1396,9 @@ def show_block_vals( Returns: Two pd.Series of endogenous and predetermined values, or `None`, `None`. + Raises: + RuntimeError: If no solution is found. + Example: .. code-block:: python @@ -1508,18 +1519,21 @@ def sensitivity( Args: i: The index of the block for which variable values will be displayed. period_index: The index of the period for which variable values will be shown. + exog_subset: List of exogenous variables to be analysed. + If `None`, all relevant exogenous variables will be analysed. method: Method for sensitivity analysis. Default is 'std'. - 'std': Adjusts variables by adding their standard deviation. - 'pct': Adjusts variables by adding 1% of their value. - 'one': Adjusts variables by adding 1 to their value. - exog_subset: List of exogenous variables to be analysed. - If None, all relevant exogenous variables will be analysed. - Returns: DataFrame showing the sensitivity of endogenous variables to exogenous variables. + Raises: + RuntimeError: If no solution is found. + ValueError: If `method` is not `std`, `pct` or `one`. + Example: .. code-block:: python @@ -1543,7 +1557,7 @@ def sensitivity( ) } except AttributeError as exc: - raise AttributeError(self._NO_SOLUTION_TEXT) from exc + raise RuntimeError(self._NO_SOLUTION_TEXT) from exc get_var_info = cache(self.gen_get_var_info(var_col_index))