From f67d3bcca083579382aafd48546da7da6402e760 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Fri, 1 Nov 2024 11:26:04 -0400 Subject: [PATCH 01/56] Improving errors in another set of `gempyor` files Includes model_info.py, outcomes.py, seeding.py, seir.py, and simulation_component.py (this last one didn't require any edits). --- .../gempyor_pkg/src/gempyor/model_info.py | 33 ++++++++----------- flepimop/gempyor_pkg/src/gempyor/outcomes.py | 22 +++++++------ flepimop/gempyor_pkg/src/gempyor/seeding.py | 8 ++--- flepimop/gempyor_pkg/src/gempyor/seir.py | 12 +++---- 4 files changed, 35 insertions(+), 40 deletions(-) diff --git a/flepimop/gempyor_pkg/src/gempyor/model_info.py b/flepimop/gempyor_pkg/src/gempyor/model_info.py index 54f981d8f..e28c22e02 100644 --- a/flepimop/gempyor_pkg/src/gempyor/model_info.py +++ b/flepimop/gempyor_pkg/src/gempyor/model_info.py @@ -11,7 +11,7 @@ def __init__(self, config: confuse.ConfigView): self.ti = config["start_date"].as_date() self.tf = config["end_date"].as_date() if self.tf <= self.ti: - raise ValueError("tf (time to finish) is less than or equal to ti (time to start)") + raise ValueError("`tf` (time to finish) is less than or equal to `ti` (time to start).") self.n_days = (self.tf - self.ti).days + 1 self.dates = pd.date_range(start=self.ti, end=self.tf, freq="D") @@ -67,9 +67,8 @@ def __init__( # Auto-detect old config if config["interventions"].exists(): raise ValueError( - """This config has an intervention section, and has been written for a previous version of flepiMoP/COVIDScenarioPipeline \ - Please use flepiMoP Version 1.1 (Commit SHA: 0c30c23937dd496d33c2b9fa7c6edb198ad80dac) to run this config. \ - (use git checkout v1.1 inside the flepiMoP directory)""" + "This config has an intervention section, which is only compatible with a previous version of flepiMoP/COVIDScenarioPipeline. " + "Please use flepiMoP Version 1.1 to run this config." ) # 1. Create a setup name that contains every scenario. @@ -94,7 +93,7 @@ def __init__( # 3. What about subpopulations subpop_config = config["subpop_setup"] if "data_path" in config: - raise ValueError("The config has a data_path section. This is no longer supported.") + raise ValueError("The config has a `data_path` section. This is no longer supported.") self.path_prefix = pathlib.Path(path_prefix) self.subpop_struct = subpopulation_structure.SubpopulationStructure( @@ -148,16 +147,14 @@ def __init__( self.seir_modifiers_library = config["seir_modifiers"]["modifiers"].get() else: self.seir_modifiers_library = config["seir_modifiers"]["modifiers"].get() - raise ValueError("Not implemented yet") # TODO create a Stacked from all + raise ValueError("This feature has not been implemented yet.") # TODO create a Stacked from all elif self.seir_modifiers_scenario is not None: - raise ValueError( - "An seir modifiers scenario was provided to ModelInfo but no 'seir_modifiers' sections in config" - ) + raise ValueError("A seir modifiers scenario was provided to `ModelInfo` but there is no `seir_modifiers` sections in config.") else: - logging.info("Running ModelInfo with seir but without SEIR Modifiers") + logging.info("Running `ModelInfo` with seir but without SEIR Modifiers") elif self.seir_modifiers_scenario is not None: - raise ValueError("A seir modifiers scenario was provided to ModelInfo but no 'seir:' sections in config") + raise ValueError("A seir modifiers scenario was provided to `ModelInfo` but there is no `seir_modifiers` sections in config.") else: logging.critical("Running ModelInfo without SEIR") @@ -171,24 +168,20 @@ def __init__( self.outcome_modifiers_library = config["outcome_modifiers"]["modifiers"].get() else: self.outcome_modifiers_library = config["outcome_modifiers"]["modifiers"].get() - raise ValueError("Not implemented yet") # TODO create a Stacked from all + raise ValueError("This feature has not been implemented yet.") # TODO create a Stacked from all ## NEED TO IMPLEMENT THIS -- CURRENTLY CANNOT USE outcome modifiers elif self.outcome_modifiers_scenario is not None: if config["outcome_modifiers"].exists(): - raise ValueError( - "An outcome modifiers scenario was provided to ModelInfo but no 'outcome_modifiers' sections in config" - ) + raise ValueError("An outcome modifiers scenario was provided to `ModelInfo` but there is no `outcome_modifiers` sections in config.") else: self.outcome_modifiers_scenario = None else: - logging.info("Running ModelInfo with outcomes but without Outcomes Modifiers") + logging.info("Running `ModelInfo` with outcomes but without Outcomes Modifiers") elif self.outcome_modifiers_scenario is not None: - raise ValueError( - "An outcome modifiers scenario was provided to ModelInfo but no 'outcomes:' sections in config" - ) + raise ValueError("An outcome modifiers scenario was provided to `ModelInfo` but there is no `outcome_modifiers` sections in config.") else: - logging.info("Running ModelInfo without Outcomes") + logging.info("Running `ModelInfo` without Outcomes") # 6. Inputs and outputs if in_run_id is None: diff --git a/flepimop/gempyor_pkg/src/gempyor/outcomes.py b/flepimop/gempyor_pkg/src/gempyor/outcomes.py index 5563f4d85..cae19c275 100644 --- a/flepimop/gempyor_pkg/src/gempyor/outcomes.py +++ b/flepimop/gempyor_pkg/src/gempyor/outcomes.py @@ -133,7 +133,7 @@ def read_parameters_from_config(modinf: model_info.ModelInfo): branching_data = pa.parquet.read_table(branching_file).to_pandas() if "relative_probability" not in list(branching_data["quantity"]): raise ValueError( - f"No 'relative_probability' quantity in {branching_file}, therefor making it useless" + f"There is no `relative_probability` quantity in '{branching_file}'." ) print( @@ -151,7 +151,7 @@ def read_parameters_from_config(modinf: model_info.ModelInfo): if len(branching_data.subpop.unique()) != len(modinf.subpop_struct.subpop_names): raise ValueError( - f"Places in seir input files does not correspond to subpops in outcome probability file {branching_file}" + f"SEIR input files do not have subpops that match those in outcome probability file '{branching_file}'." ) parameters = {} @@ -167,7 +167,9 @@ def read_parameters_from_config(modinf: model_info.ModelInfo): else: raise ValueError( - f"unsure how to read outcome {new_comp}: not a str, nor an incidence or prevalence: {src_name}" + f"Unable to read outcome '{new_comp}': " + f"expected a string or dictionary containing `incidence` or `prevalence`. " + f"Recieved: '{src_name}'." ) parameters[new_comp]["probability"] = outcomes_config[new_comp]["probability"]["value"] @@ -248,7 +250,7 @@ def read_parameters_from_config(modinf: model_info.ModelInfo): parameters[new_comp] = {} parameters[new_comp]["sum"] = outcomes_config[new_comp]["sum"].get() else: - raise ValueError(f"No 'source' or 'sum' specified for comp {new_comp}") + raise ValueError(f"No `source` or `sum` specified for comp '{new_comp}'.") return parameters @@ -348,14 +350,14 @@ def compute_all_multioutcomes( outcome_name=new_comp, ) else: - raise ValueError(f"Unknown type for seir simulation provided, got f{type(seir_sim)}") + raise ValueError(f"Unknown type provided for seir simulation, received '{type(seir_sim)}'.") # we don't keep source in this cases else: # already defined outcomes if source_name in all_data: source_array = all_data[source_name] else: raise ValueError( - f"ERROR with outcome {new_comp}: the specified source {source_name} is not a dictionnary (for seir outcome) nor an existing pre-identified outcomes." + f"Issue with outcome '{new_comp}'; the specified source '{source_name}' is neither a dictionnary (for seir outcome) nor an existing pre-identified outcome." ) if (loaded_values is not None) and (new_comp in loaded_values["outcome"].values): @@ -510,7 +512,7 @@ def filter_seir_df(diffI, dates, subpops, filters, outcome_name) -> np.ndarray: vtype = "prevalence" else: raise ValueError( - f"Cannot distinguish the source of outcome {outcome_name}: it is not another previously defined outcome and there is no 'incidence:' or 'prevalence:'." + f"Cannot discern the source of outcome '{outcome_name}'; it is not a previously defined outcome and there is no `incidence` or `prevalence`." ) diffI = diffI[diffI["mc_value_type"] == vtype] @@ -539,7 +541,7 @@ def filter_seir_xr(diffI, dates, subpops, filters, outcome_name) -> np.ndarray: vtype = "prevalence" else: raise ValueError( - f"Cannot distinguish the source of outcome {outcome_name}: it is not another previously defined outcome and there is no 'incidence:' or 'prevalence:'." + f"Cannot discern the source of outcome '{outcome_name}'; it is not a previously defined outcome and there is no `incidence` or `prevalence`." ) # Filter the data filters = filters[vtype] @@ -587,7 +589,7 @@ def multishiftee(arr, shifts, stoch_delay_flag=True): result = np.zeros_like(arr) if stoch_delay_flag: - raise ValueError("NOT SUPPORTED YET") + raise ValueError("`stoch_delay_flag` not supported yet.") # for i, row in reversed(enumerate(np.rows(arr))): # for j,elem in reversed(enumerate(row)): ## This function takes in : @@ -613,7 +615,7 @@ def multishift(arr, shifts, stoch_delay_flag=True): result = np.zeros_like(arr) if stoch_delay_flag: - raise ValueError("NOT SUPPORTED YET") + raise ValueError("`stoch_delay_flag` not supported yet.") # for i, row in reversed(enumerate(np.rows(arr))): # for j,elem in reversed(enumerate(row)): ## This function takes in : diff --git a/flepimop/gempyor_pkg/src/gempyor/seeding.py b/flepimop/gempyor_pkg/src/gempyor/seeding.py index fe58657c0..bb774e0b5 100644 --- a/flepimop/gempyor_pkg/src/gempyor/seeding.py +++ b/flepimop/gempyor_pkg/src/gempyor/seeding.py @@ -17,7 +17,7 @@ def _DataFrame2NumbaDict(df, amounts, modinf) -> nb.typed.Dict: if not df["date"].is_monotonic_increasing: - raise ValueError("_DataFrame2NumbaDict got an unsorted dataframe, exposing itself to non-sense") + raise ValueError("`_DataFrame2NumbaDict` got an unsorted dataframe.") cmp_grp_names = [col for col in modinf.compartments.compartments.columns if col != "name"] seeding_dict: nb.typed.Dict = nb.typed.Dict.empty( @@ -97,7 +97,7 @@ def get_from_config(self, sim_id: int, modinf) -> nb.typed.Dict: ) dupes = seeding[seeding.duplicated(["subpop", "date"])].index + 1 if not dupes.empty: - raise ValueError(f"Repeated subpop-date in rows {dupes.tolist()} of seeding::lambda_file.") + raise ValueError(f"There are repeating subpop-date in rows '{dupes.tolist()}' of `seeding::lambda_file`.") elif method == "FolderDraw": seeding = pd.read_csv( self.path_prefix @@ -121,7 +121,7 @@ def get_from_config(self, sim_id: int, modinf) -> nb.typed.Dict: seeding = pd.DataFrame(columns=["date", "subpop"]) return _DataFrame2NumbaDict(df=seeding, amounts=[], modinf=modinf) else: - raise NotImplementedError(f"unknown seeding method [got: {method}]") + raise NotImplementedError(f"Unknown seeding method [received: '{method}'].") # Sorting by date is very important here for the seeding format necessary !!!! # print(seeding.shape) @@ -142,7 +142,7 @@ def get_from_config(self, sim_id: int, modinf) -> nb.typed.Dict: elif method == "FolderDraw" or method == "FromFile": amounts = seeding["amount"] else: - raise ValueError(f"Unknown seeding method: {method}") + raise ValueError(f"Unknown seeding method [received: '{method}'].") return _DataFrame2NumbaDict(df=seeding, amounts=amounts, modinf=modinf) diff --git a/flepimop/gempyor_pkg/src/gempyor/seir.py b/flepimop/gempyor_pkg/src/gempyor/seir.py index 4e59761f2..80b8c1021 100644 --- a/flepimop/gempyor_pkg/src/gempyor/seir.py +++ b/flepimop/gempyor_pkg/src/gempyor/seir.py @@ -31,7 +31,7 @@ def build_step_source_arg( if integration_method == "rk4": integration_method = "rk4.jit" if integration_method not in ["rk4.jit", "legacy"]: - raise ValueError(f"Unknown integration method {integration_method}.") + raise ValueError(f"Unknown integration method [received: '{integration_method}'].") if "dt" in modinf.seir_config["integration"].keys(): dt = float( eval(str(modinf.seir_config["integration"]["dt"].get())) @@ -143,8 +143,8 @@ def steps_SEIR( elif integration_method == "rk4.jit": if modinf.stoch_traj_flag == True: raise ValueError( - f"with method {integration_method}, only deterministic " - f"integration is possible (got stoch_straj_flag={modinf.stoch_traj_flag}" + f"With method '{integration_method}', only deterministic " + f"integration is possible (received `stoch_straj_flag` = '{modinf.stoch_traj_flag}')." ) seir_sim = steps_rk4.rk4_integration(**fnct_args, silent=True) else: @@ -159,8 +159,8 @@ def steps_SEIR( ]: if modinf.stoch_traj_flag == True: raise ValueError( - f"with method {integration_method}, only deterministic " - f"integration is possible (got stoch_straj_flag={modinf.stoch_traj_flag}" + f"With method '{integration_method}', only deterministic " + f"integration is possible (received `stoch_straj_flag` = '{modinf.stoch_traj_flag}')." ) seir_sim = steps_experimental.ode_integration(**fnct_args, integration_method=integration_method) elif integration_method == "rk4.jit1": @@ -180,7 +180,7 @@ def steps_SEIR( elif integration_method == "rk4_aot": seir_sim = steps_experimental.rk4_aot(**fnct_args) else: - raise ValueError(f"Unknow integration scheme, got {integration_method}") + raise ValueError(f"Unknown integration method [received '{integration_method}'].") # We return an xarray instead of a ndarray now compartment_coords = {} From 90b361819fe6f8918513ffbd40a8418e3e86b710 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Fri, 8 Nov 2024 14:08:13 -0500 Subject: [PATCH 02/56] Applied `black` linting to this branch --- .../gempyor_pkg/src/gempyor/compartments.py | 68 +++++++++++++----- .../src/gempyor/config_validator.py | 69 +++++++++++-------- .../src/gempyor/initial_conditions.py | 27 +++++--- .../gempyor_pkg/src/gempyor/model_info.py | 44 +++++++++--- flepimop/gempyor_pkg/src/gempyor/outcomes.py | 8 ++- .../gempyor_pkg/src/gempyor/parameters.py | 2 +- flepimop/gempyor_pkg/src/gempyor/seeding.py | 4 +- flepimop/gempyor_pkg/src/gempyor/seir.py | 8 ++- .../tests/parameters/test_parameters_class.py | 4 +- flepimop/gempyor_pkg/tests/seir/test_ic.py | 5 +- 10 files changed, 164 insertions(+), 75 deletions(-) diff --git a/flepimop/gempyor_pkg/src/gempyor/compartments.py b/flepimop/gempyor_pkg/src/gempyor/compartments.py index 7f19e8508..a379781f8 100644 --- a/flepimop/gempyor_pkg/src/gempyor/compartments.py +++ b/flepimop/gempyor_pkg/src/gempyor/compartments.py @@ -152,9 +152,15 @@ def expand_transition_elements(self, single_transition_config, problem_dimension ) except Exception as e: print(f"Error {e}:") - print(f">>> in expand_transition_elements for `source:` at index '{it.multi_index}'") - print(f">>> this transition source is: '{single_transition_config['source']}'") - print(f">>> this transition destination is: '{single_transition_config['destination']}'") + print( + f">>> in expand_transition_elements for `source:` at index '{it.multi_index}'" + ) + print( + f">>> this transition source is: '{single_transition_config['source']}'" + ) + print( + f">>> this transition destination is: '{single_transition_config['destination']}'" + ) print(f"transition_dimension: '{problem_dimension}'") raise e @@ -168,9 +174,15 @@ def expand_transition_elements(self, single_transition_config, problem_dimension ) except Exception as e: print(f"Error {e}:") - print(f">>> in expand_transition_elements for `destination:` at index '{it.multi_index}'") - print(f">>> this transition source is: '{single_transition_config['source']}'") - print(f">>> this transition destination is: '{single_transition_config['destination']}'") + print( + f">>> in expand_transition_elements for `destination:` at index '{it.multi_index}'" + ) + print( + f">>> this transition source is: '{single_transition_config['source']}'" + ) + print( + f">>> this transition destination is: '{single_transition_config['destination']}'" + ) print(f"transition_dimension: '{problem_dimension}'") raise e @@ -184,9 +196,15 @@ def expand_transition_elements(self, single_transition_config, problem_dimension ) except Exception as e: print(f"Error {e}:") - print(f">>> in expand_transition_elements for `rate:` at index '{it.multi_index}'") - print(f">>> this transition source is: '{single_transition_config['source']}'") - print(f">>> this transition destination is: '{single_transition_config['destination']}'") + print( + f">>> in expand_transition_elements for `rate:` at index '{it.multi_index}'" + ) + print( + f">>> this transition source is: '{single_transition_config['source']}'" + ) + print( + f">>> this transition destination is: '{single_transition_config['destination']}'" + ) print(f"transition_dimension: '{problem_dimension}'") raise e @@ -206,9 +224,15 @@ def expand_transition_elements(self, single_transition_config, problem_dimension ) except Exception as e: print(f"Error {e}:") - print(f">>> in expand_transition_elements for `proportional_to:` at index '{it.multi_index}'") - print(f">>> this transition source is: '{single_transition_config['source']}'") - print(f">>> this transition destination is: '{single_transition_config['destination']}'") + print( + f">>> in expand_transition_elements for `proportional_to:` at index '{it.multi_index}'" + ) + print( + f">>> this transition source is: '{single_transition_config['source']}'" + ) + print( + f">>> this transition destination is: '{single_transition_config['destination']}'" + ) print(f"transition_dimension: '{problem_dimension}'") raise e @@ -235,9 +259,15 @@ def expand_transition_elements(self, single_transition_config, problem_dimension ) except Exception as e: print(f"Error {e}:") - print(f">>> in expand_transition_elements for `proportion_exponent:` at index '{it.multi_index}'") - print(f">>> this transition source is: '{single_transition_config['source']}'") - print(f">>> this transition destination is: '{single_transition_config['destination']}'") + print( + f">>> in expand_transition_elements for `proportion_exponent:` at index '{it.multi_index}'" + ) + print( + f">>> this transition source is: '{single_transition_config['source']}'" + ) + print( + f">>> this transition destination is: '{single_transition_config['destination']}'" + ) print(f"transition_dimension: '{problem_dimension}'") raise e else: @@ -475,7 +505,9 @@ def get_transition_array(self): if self.compartments["name"][compartment] == elem: rc = compartment if rc == -1: - raise ValueError(f"Could not find '{colname}' defined by '{elem}' in '{self.compartments}'.") + raise ValueError( + f"Could not find '{colname}' defined by '{elem}' in '{self.compartments}'." + ) transition_array[cit, it] = rc unique_strings = [] @@ -557,7 +589,7 @@ def get_transition_array(self): if candidate not in unique_strings: raise ValueError( f"Proportion exponent '{candidate}' is not found in the list of unique strings: '{unique_strings}'." - ) + ) rc = [it for it, x in enumerate(unique_strings) if x == candidate][0] proportion_info[2][proportion_compartment_index] = rc proportion_compartment_index += 1 @@ -707,7 +739,7 @@ def parse_parameter_strings_to_numpy_arrays( not operators ): # empty list means all have been tried. Usually there just remains one string in string_list at that time. raise ValueError( - f"Could not parse string '{string_list}'. " + f"Could not parse string '{string_list}'. " f"This usually mean that '{string_list[0]}' is a parameter name that is not defined " f"or that it contains an operator that is not in the list of supported operators: ^,*,/,+,-. " f"The defined parameters are '{parameter_names}'." diff --git a/flepimop/gempyor_pkg/src/gempyor/config_validator.py b/flepimop/gempyor_pkg/src/gempyor/config_validator.py index 3c105ba55..3803cae94 100644 --- a/flepimop/gempyor_pkg/src/gempyor/config_validator.py +++ b/flepimop/gempyor_pkg/src/gempyor/config_validator.py @@ -65,20 +65,27 @@ class InitialConditionsConfig(BaseModel): @model_validator(mode="before") def validate_initial_file_check(cls, values): - method = values.get('method') - initial_conditions_file = values.get('initial_conditions_file') - initial_file_type = values.get('initial_file_type') - if method in {'FromFile', 'SetInitialConditions'} and not initial_conditions_file: - raise ValueError(f"An `initial_conditions_file` is required when method is '{method}'.") - if method in {'InitialConditionsFolderDraw','SetInitialConditionsFolderDraw'} and not initial_file_type: - raise ValueError(f"An `initial_file_type` is required when method is '{method}'.") + method = values.get("method") + initial_conditions_file = values.get("initial_conditions_file") + initial_file_type = values.get("initial_file_type") + if method in {"FromFile", "SetInitialConditions"} and not initial_conditions_file: + raise ValueError( + f"An `initial_conditions_file` is required when method is '{method}'." + ) + if ( + method in {"InitialConditionsFolderDraw", "SetInitialConditionsFolderDraw"} + and not initial_file_type + ): + raise ValueError( + f"An `initial_file_type` is required when method is '{method}'." + ) return values @model_validator(mode="before") def plugin_filecheck(cls, values): - method = values.get('method') - plugin_file_path = values.get('plugin_file_path') - if method == 'plugin' and not plugin_file_path: + method = values.get("method") + plugin_file_path = values.get("plugin_file_path") + if method == "plugin" and not plugin_file_path: raise ValueError("A plugin file path is required when method is plugin.") return values @@ -106,21 +113,21 @@ class SeedingConfig(BaseModel): @model_validator(mode="before") def validate_seedingfile(cls, values): - method = values.get('method') - lambda_file = values.get('lambda_file') - seeding_file_type = values.get('seeding_file_type') - seeding_file = values.get('seeding_file') - if method == 'PoissonDistributed' and not lambda_file: + method = values.get("method") + lambda_file = values.get("lambda_file") + seeding_file_type = values.get("seeding_file_type") + seeding_file = values.get("seeding_file") + if method == "PoissonDistributed" and not lambda_file: raise ValueError( f"A `lambda_file` is required when method is '{method}', " f"was given '{lambda_file}'." ) - if method == 'FolderDraw' and not seeding_file_type: + if method == "FolderDraw" and not seeding_file_type: raise ValueError( f"A `seeding_file_type` is required when method is 'FolderDraw', " f"was given '{seeding_file_type}'." ) - if method == 'FromFile' and not seeding_file: + if method == "FromFile" and not seeding_file: raise ValueError( f"A `seeding_file` is required when method is 'FromFile', " f"was given '{seeding_file}'." @@ -129,9 +136,9 @@ def validate_seedingfile(cls, values): @model_validator(mode="before") def plugin_filecheck(cls, values): - method = values.get('method') - plugin_file_path = values.get('plugin_file_path') - if method == 'plugin' and not plugin_file_path: + method = values.get("method") + plugin_file_path = values.get("plugin_file_path") + if method == "plugin" and not plugin_file_path: raise ValueError( f"A plugin file path is required when method is 'plugin', " f"was given '{plugin_file_path!r}'." @@ -167,10 +174,14 @@ def check_distr(cls, values): b = values.get("b") if distr != "fixed": if not mean and not sd: - raise ValueError("Mean and sd must be provided for non-fixed distributions.") - if distr == 'truncnorm' and not a and not b: - raise ValueError("a and b must be provided for truncated normal distributions.") - if distr == 'fixed' and not value: + raise ValueError( + "Mean and sd must be provided for non-fixed distributions." + ) + if distr == "truncnorm" and not a and not b: + raise ValueError( + "a and b must be provided for truncated normal distributions." + ) + if distr == "fixed" and not value: raise ValueError("Value must be provided for fixed distributions.") return values @@ -348,7 +359,9 @@ def check_paramfromfile_type(cls, values): param_subpop_file = values.get("param_subpop_file") is not None if param_from_file and not param_subpop_file: - raise ValueError("A `param_subpop_file` is required when `param_from_file` is 'True'.") + raise ValueError( + "A `param_subpop_file` is required when `param_from_file` is 'True'." + ) return values @@ -432,7 +445,9 @@ def verify_inference(cls, values): inference_present = values.get("inference") is not None start_date_groundtruth = values.get("start_date_groundtruth") is not None if inference_present and not start_date_groundtruth: - raise ValueError("Inference mode is enabled, but no groundtruth dates are provided. Please provide groundtruth dates.") + raise ValueError( + "Inference mode is enabled, but no groundtruth dates are provided. Please provide groundtruth dates." + ) elif start_date_groundtruth and not inference_present: raise ValueError( "Groundtruth dates are provided, but inference mode is not enabled. Please enable inference mode." @@ -457,5 +472,5 @@ def init_or_seed(cls, values): if not init or seed: raise ValueError( f"At least one of `initial_conditions` or `seeding` must be provided." - ) + ) return values diff --git a/flepimop/gempyor_pkg/src/gempyor/initial_conditions.py b/flepimop/gempyor_pkg/src/gempyor/initial_conditions.py index cc40f1a82..1926b5513 100644 --- a/flepimop/gempyor_pkg/src/gempyor/initial_conditions.py +++ b/flepimop/gempyor_pkg/src/gempyor/initial_conditions.py @@ -116,7 +116,9 @@ def get_from_config(self, sim_id: int, modinf) -> np.ndarray: allow_missing_subpops=self.allow_missing_subpops, ) else: - raise NotImplementedError(f"Unknown initial conditions method [received: '{method}'].") + raise NotImplementedError( + f"Unknown initial conditions method [received: '{method}']." + ) # check that the inputed values sums to the subpop population: check_population( @@ -147,13 +149,14 @@ def check_population(y0, modinf, ignore_population_checks=False): ) if error and not ignore_population_checks: - raise ValueError("Geodata and initial condition do not agree on population size. Use `ignore_population_checks: True` to ignore." + raise ValueError( + "Geodata and initial condition do not agree on population size. Use `ignore_population_checks: True` to ignore." ) elif error and ignore_population_checks: warnings.warn( - "Population mismatch errors ignored because `ignore_population_checks` is set to `True`. " - "Execution will continue, but this is not recommended.", - UserWarning + "Population mismatch errors ignored because `ignore_population_checks` is set to `True`. " + "Execution will continue, but this is not recommended.", + UserWarning, ) @@ -201,7 +204,9 @@ def read_initial_condition_from_tidydataframe( logger.critical( f"No initial conditions for for subpop {pl}, assuming everyone (n={modinf.subpop_pop[pl_idx]}) in the first metacompartment ({modinf.compartments.compartments['name'].iloc[0]})" ) - raise RuntimeError("There is a bug; report this message. Past implemenation was buggy.") + raise RuntimeError( + "There is a bug; report this message. Past implemenation was buggy." + ) # TODO: this is probably ok but highlighting for consistency if "proportional" in self.initial_conditions_config.keys(): if self.initial_conditions_config["proportional"].get(): @@ -258,8 +263,10 @@ def read_initial_condition_from_seir_output( (ic_df["date"] == str(modinf.ti)) & (ic_df["mc_value_type"] == "prevalence") ] if ic_df.empty: - raise ValueError(f"No entry provided for initial time `ti` in the `initial_conditions::states_file.` " - f"`ti`: '{modinf.ti}'.") + raise ValueError( + f"No entry provided for initial time `ti` in the `initial_conditions::states_file.` " + f"`ti`: '{modinf.ti}'." + ) y0 = np.zeros((modinf.compartments.compartments.shape[0], modinf.nsubpops)) for comp_idx, comp_name in modinf.compartments.compartments["name"].items(): @@ -299,7 +306,9 @@ def read_initial_condition_from_seir_output( if pl in ic_df.columns: y0[comp_idx, pl_idx] = float(ic_df_compartment[pl].iloc[0]) elif allow_missing_subpops: - raise RuntimeError("There is a bug; report this message. Past implemenation was buggy") + raise RuntimeError( + "There is a bug; report this message. Past implemenation was buggy" + ) # TODO this should set the full subpop, not just the 0th commpartment logger.critical( f"No initial conditions for for subpop {pl}, assuming everyone (n={modinf.subpop_pop[pl_idx]}) in the first metacompartments ({modinf.compartments.compartments['name'].iloc[0]})" diff --git a/flepimop/gempyor_pkg/src/gempyor/model_info.py b/flepimop/gempyor_pkg/src/gempyor/model_info.py index dc0008e1e..74df06669 100644 --- a/flepimop/gempyor_pkg/src/gempyor/model_info.py +++ b/flepimop/gempyor_pkg/src/gempyor/model_info.py @@ -18,7 +18,9 @@ def __init__(self, config: confuse.ConfigView): self.ti = config["start_date"].as_date() self.tf = config["end_date"].as_date() if self.tf <= self.ti: - raise ValueError("`tf` (time to finish) is less than or equal to `ti` (time to start).") + raise ValueError( + "`tf` (time to finish) is less than or equal to `ti` (time to start)." + ) self.n_days = (self.tf - self.ti).days + 1 self.dates = pd.date_range(start=self.ti, end=self.tf, freq="D") @@ -100,7 +102,9 @@ def __init__( # 3. What about subpopulations subpop_config = config["subpop_setup"] if "data_path" in config: - raise ValueError("The config has a `data_path` section. This is no longer supported.") + raise ValueError( + "The config has a `data_path` section. This is no longer supported." + ) self.path_prefix = pathlib.Path(path_prefix) self.subpop_struct = subpopulation_structure.SubpopulationStructure( @@ -161,15 +165,23 @@ def __init__( "modifiers" ].get() else: - self.seir_modifiers_library = config["seir_modifiers"]["modifiers"].get() - raise ValueError("This feature has not been implemented yet.") # TODO create a Stacked from all + self.seir_modifiers_library = config["seir_modifiers"][ + "modifiers" + ].get() + raise ValueError( + "This feature has not been implemented yet." + ) # TODO create a Stacked from all elif self.seir_modifiers_scenario is not None: - raise ValueError("A seir modifiers scenario was provided to `ModelInfo` but there is no `seir_modifiers` sections in config.") + raise ValueError( + "A seir modifiers scenario was provided to `ModelInfo` but there is no `seir_modifiers` sections in config." + ) else: logging.info("Running `ModelInfo` with seir but without SEIR Modifiers") elif self.seir_modifiers_scenario is not None: - raise ValueError("A seir modifiers scenario was provided to `ModelInfo` but there is no `seir_modifiers` sections in config.") + raise ValueError( + "A seir modifiers scenario was provided to `ModelInfo` but there is no `seir_modifiers` sections in config." + ) else: logging.critical("Running ModelInfo without SEIR") @@ -186,19 +198,29 @@ def __init__( "modifiers" ].get() else: - self.outcome_modifiers_library = config["outcome_modifiers"]["modifiers"].get() - raise ValueError("This feature has not been implemented yet.") # TODO create a Stacked from all + self.outcome_modifiers_library = config["outcome_modifiers"][ + "modifiers" + ].get() + raise ValueError( + "This feature has not been implemented yet." + ) # TODO create a Stacked from all ## NEED TO IMPLEMENT THIS -- CURRENTLY CANNOT USE outcome modifiers elif self.outcome_modifiers_scenario is not None: if config["outcome_modifiers"].exists(): - raise ValueError("An outcome modifiers scenario was provided to `ModelInfo` but there is no `outcome_modifiers` sections in config.") + raise ValueError( + "An outcome modifiers scenario was provided to `ModelInfo` but there is no `outcome_modifiers` sections in config." + ) else: self.outcome_modifiers_scenario = None else: - logging.info("Running `ModelInfo` with outcomes but without Outcomes Modifiers") + logging.info( + "Running `ModelInfo` with outcomes but without Outcomes Modifiers" + ) elif self.outcome_modifiers_scenario is not None: - raise ValueError("An outcome modifiers scenario was provided to `ModelInfo` but there is no `outcome_modifiers` sections in config.") + raise ValueError( + "An outcome modifiers scenario was provided to `ModelInfo` but there is no `outcome_modifiers` sections in config." + ) else: logging.info("Running `ModelInfo` without Outcomes") diff --git a/flepimop/gempyor_pkg/src/gempyor/outcomes.py b/flepimop/gempyor_pkg/src/gempyor/outcomes.py index 9429c589c..aeb7e0032 100644 --- a/flepimop/gempyor_pkg/src/gempyor/outcomes.py +++ b/flepimop/gempyor_pkg/src/gempyor/outcomes.py @@ -185,8 +185,8 @@ def read_parameters_from_config(modinf: model_info.ModelInfo): else: raise ValueError( f"Unable to read outcome '{new_comp}': " - f"expected a string or dictionary containing `incidence` or `prevalence`. " - f"Recieved: '{src_name}'." + f"expected a string or dictionary containing `incidence` or `prevalence`. " + f"Recieved: '{src_name}'." ) parameters[new_comp]["probability"] = outcomes_config[new_comp][ @@ -397,7 +397,9 @@ def compute_all_multioutcomes( outcome_name=new_comp, ) else: - raise ValueError(f"Unknown type provided for seir simulation, received '{type(seir_sim)}'.") + raise ValueError( + f"Unknown type provided for seir simulation, received '{type(seir_sim)}'." + ) # we don't keep source in this cases else: # already defined outcomes if source_name in all_data: diff --git a/flepimop/gempyor_pkg/src/gempyor/parameters.py b/flepimop/gempyor_pkg/src/gempyor/parameters.py index 2c2c37721..7ab0de151 100644 --- a/flepimop/gempyor_pkg/src/gempyor/parameters.py +++ b/flepimop/gempyor_pkg/src/gempyor/parameters.py @@ -127,7 +127,7 @@ def __init__( print("config dates:", pd.date_range(ti, tf)) print("loaded dates:", df.index) raise ValueError( - f"Issue loading file '{fn_name}' for parameter '{pn}': " + f"Issue loading file '{fn_name}' for parameter '{pn}': " f"Provided file dates span '{str(df.index[0])}' to '{str(df.index[-1])}', " f"but the config dates span '{ti}' to '{tf}'." ) diff --git a/flepimop/gempyor_pkg/src/gempyor/seeding.py b/flepimop/gempyor_pkg/src/gempyor/seeding.py index 7fd8486af..5d0653d0e 100644 --- a/flepimop/gempyor_pkg/src/gempyor/seeding.py +++ b/flepimop/gempyor_pkg/src/gempyor/seeding.py @@ -108,7 +108,9 @@ def get_from_config(self, sim_id: int, modinf) -> nb.typed.Dict: ) dupes = seeding[seeding.duplicated(["subpop", "date"])].index + 1 if not dupes.empty: - raise ValueError(f"There are repeating subpop-date in rows '{dupes.tolist()}' of `seeding::lambda_file`.") + raise ValueError( + f"There are repeating subpop-date in rows '{dupes.tolist()}' of `seeding::lambda_file`." + ) elif method == "FolderDraw": seeding = pd.read_csv( self.path_prefix diff --git a/flepimop/gempyor_pkg/src/gempyor/seir.py b/flepimop/gempyor_pkg/src/gempyor/seir.py index 5064231bc..bb06cdfa5 100644 --- a/flepimop/gempyor_pkg/src/gempyor/seir.py +++ b/flepimop/gempyor_pkg/src/gempyor/seir.py @@ -31,7 +31,9 @@ def build_step_source_arg( if integration_method == "rk4": integration_method = "rk4.jit" if integration_method not in ["rk4.jit", "legacy"]: - raise ValueError(f"Unknown integration method [received: '{integration_method}'].") + raise ValueError( + f"Unknown integration method [received: '{integration_method}']." + ) if "dt" in modinf.seir_config["integration"].keys(): dt = float( eval(str(modinf.seir_config["integration"]["dt"].get())) @@ -187,7 +189,9 @@ def steps_SEIR( elif integration_method == "rk4_aot": seir_sim = steps_experimental.rk4_aot(**fnct_args) else: - raise ValueError(f"Unknown integration method [received '{integration_method}'].") + raise ValueError( + f"Unknown integration method [received '{integration_method}']." + ) # We return an xarray instead of a ndarray now compartment_coords = {} diff --git a/flepimop/gempyor_pkg/tests/parameters/test_parameters_class.py b/flepimop/gempyor_pkg/tests/parameters/test_parameters_class.py index e18cdaca2..f82cf2a27 100644 --- a/flepimop/gempyor_pkg/tests/parameters/test_parameters_class.py +++ b/flepimop/gempyor_pkg/tests/parameters/test_parameters_class.py @@ -237,8 +237,8 @@ def test_timeseries_parameter_has_insufficient_columns_value_error( with pytest.raises( ValueError, match=( - rf"^Issue loading file '{tmp_file}' for parameter 'sigma': " - rf"the number of non-'date' columns is '{actual_columns}', expected '{mock_inputs.number_of_subpops()}' " + rf"^Issue loading file '{tmp_file}' for parameter 'sigma': " + rf"the number of non-'date' columns is '{actual_columns}', expected '{mock_inputs.number_of_subpops()}' " rf"\(number of subpopulations\) or one\.$" ), ): diff --git a/flepimop/gempyor_pkg/tests/seir/test_ic.py b/flepimop/gempyor_pkg/tests/seir/test_ic.py index 0dc29f956..fc478efb9 100644 --- a/flepimop/gempyor_pkg/tests/seir/test_ic.py +++ b/flepimop/gempyor_pkg/tests/seir/test_ic.py @@ -48,7 +48,10 @@ def test_IC_allow_missing_node_compartments_success(self): sic.get_from_config(sim_id=100, modinf=s) def test_IC_IC_notImplemented_fail(self): - with pytest.raises(NotImplementedError, match=r"^Unknown initial conditions method \[received: .*?\]\.$"): + with pytest.raises( + NotImplementedError, + match=r"^Unknown initial conditions method \[received: .*?\]\.$", + ): config.clear() config.read(user=False) config.set_file(f"{DATA_DIR}/config.yml") From a6c358548585b85b7818aabcf798b84eb4221734 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Fri, 8 Nov 2024 14:34:09 -0500 Subject: [PATCH 03/56] Updating a RegEx in `test_model_info.py` --- flepimop/gempyor_pkg/tests/seir/test_model_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/seir/test_model_info.py b/flepimop/gempyor_pkg/tests/seir/test_model_info.py index 3fbf21a75..28855f2f4 100644 --- a/flepimop/gempyor_pkg/tests/seir/test_model_info.py +++ b/flepimop/gempyor_pkg/tests/seir/test_model_info.py @@ -44,7 +44,7 @@ def test_ModelInfo_init_tf_is_ahead_of_ti_fail(self): config.read(user=False) config.set_file(f"{DATA_DIR}/config_test.yml") config["start_date"] = "2022-01-02" - with pytest.raises(ValueError, match=r"tf.*is less than or equal to ti.*"): + with pytest.raises(ValueError, match=r"`tf`\s?\(time to finish\)\s?is less than or equal to\s?`ti`\s?\(time to start\)\."): s = ModelInfo( config=config, seir_modifiers_scenario=None, From e2a87c3f71fae83858f3269305e3139d15fdcc9b Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Fri, 8 Nov 2024 14:40:03 -0500 Subject: [PATCH 04/56] `black` linting and RegEx alteration --- flepimop/gempyor_pkg/tests/seir/test_model_info.py | 5 ++++- flepimop/gempyor_pkg/tests/seir/test_seir.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/flepimop/gempyor_pkg/tests/seir/test_model_info.py b/flepimop/gempyor_pkg/tests/seir/test_model_info.py index 28855f2f4..4790063eb 100644 --- a/flepimop/gempyor_pkg/tests/seir/test_model_info.py +++ b/flepimop/gempyor_pkg/tests/seir/test_model_info.py @@ -44,7 +44,10 @@ def test_ModelInfo_init_tf_is_ahead_of_ti_fail(self): config.read(user=False) config.set_file(f"{DATA_DIR}/config_test.yml") config["start_date"] = "2022-01-02" - with pytest.raises(ValueError, match=r"`tf`\s?\(time to finish\)\s?is less than or equal to\s?`ti`\s?\(time to start\)\."): + with pytest.raises( + ValueError, + match=r"`tf`\s?\(time to finish\)\s?is less than or equal to\s?`ti`\s?\(time to start\)\.", + ): s = ModelInfo( config=config, seir_modifiers_scenario=None, diff --git a/flepimop/gempyor_pkg/tests/seir/test_seir.py b/flepimop/gempyor_pkg/tests/seir/test_seir.py index d9d6d696f..8b772a689 100644 --- a/flepimop/gempyor_pkg/tests/seir/test_seir.py +++ b/flepimop/gempyor_pkg/tests/seir/test_seir.py @@ -128,7 +128,7 @@ def test_constant_population_legacy_integration(): def test_constant_population_rk4jit_integration_fail(): - with pytest.raises(ValueError, match=r".*with.*method.*integration.*"): + with pytest.raises(ValueError, match=r".*With.*method.*integration.*"): config.set_file(f"{DATA_DIR}/config.yml") first_sim_index = 1 From 17a4f384686b61ccc9cde171aac02f718c4ce3b7 Mon Sep 17 00:00:00 2001 From: Emily Przykucki <100221052+emprzy@users.noreply.github.com> Date: Wed, 13 Nov 2024 11:34:32 -0500 Subject: [PATCH 05/56] Update flepimop/gempyor_pkg/src/gempyor/seir.py Co-authored-by: Timothy Willard <9395586+TimothyWillard@users.noreply.github.com> --- flepimop/gempyor_pkg/src/gempyor/seir.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/flepimop/gempyor_pkg/src/gempyor/seir.py b/flepimop/gempyor_pkg/src/gempyor/seir.py index bb06cdfa5..182af3418 100644 --- a/flepimop/gempyor_pkg/src/gempyor/seir.py +++ b/flepimop/gempyor_pkg/src/gempyor/seir.py @@ -150,8 +150,7 @@ def steps_SEIR( elif integration_method == "rk4.jit": if modinf.stoch_traj_flag == True: raise ValueError( - f"With method '{integration_method}', only deterministic " - f"integration is possible (received `stoch_straj_flag` = '{modinf.stoch_traj_flag}')." + f"'{integration_method}' integration method only supports deterministic integration, but `stoch_straj_flag` is '{modinf.stoch_traj_flag}'." ) seir_sim = steps_rk4.rk4_integration(**fnct_args, silent=True) else: From 3acad126401cc13af08069e74752c230b3575e96 Mon Sep 17 00:00:00 2001 From: Emily Przykucki <100221052+emprzy@users.noreply.github.com> Date: Wed, 13 Nov 2024 11:35:37 -0500 Subject: [PATCH 06/56] Update flepimop/gempyor_pkg/src/gempyor/seir.py Co-authored-by: Timothy Willard <9395586+TimothyWillard@users.noreply.github.com> --- flepimop/gempyor_pkg/src/gempyor/seir.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/flepimop/gempyor_pkg/src/gempyor/seir.py b/flepimop/gempyor_pkg/src/gempyor/seir.py index 182af3418..da62c9101 100644 --- a/flepimop/gempyor_pkg/src/gempyor/seir.py +++ b/flepimop/gempyor_pkg/src/gempyor/seir.py @@ -165,8 +165,7 @@ def steps_SEIR( ]: if modinf.stoch_traj_flag == True: raise ValueError( - f"With method '{integration_method}', only deterministic " - f"integration is possible (received `stoch_straj_flag` = '{modinf.stoch_traj_flag}')." + f"'{integration_method}' integration method only supports deterministic integration, but `stoch_straj_flag` is '{modinf.stoch_traj_flag}'." ) seir_sim = steps_experimental.ode_integration( **fnct_args, integration_method=integration_method From 44ccc848df6e64af5082abc52206582202838be1 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Wed, 13 Nov 2024 11:54:31 -0500 Subject: [PATCH 07/56] Implementing Tim's suggestions! --- .../gempyor_pkg/src/gempyor/model_info.py | 19 ++++---- flepimop/gempyor_pkg/src/gempyor/outcomes.py | 9 ++-- flepimop/gempyor_pkg/src/gempyor/seeding.py | 4 +- .../gempyor_pkg/src/gempyor/statistics.py | 18 ++++--- flepimop/gempyor_pkg/src/gempyor/utils.py | 47 +++++++++---------- flepimop/gempyor_pkg/tests/seir/test_seir.py | 2 +- 6 files changed, 50 insertions(+), 49 deletions(-) diff --git a/flepimop/gempyor_pkg/src/gempyor/model_info.py b/flepimop/gempyor_pkg/src/gempyor/model_info.py index 74df06669..f22e16d1d 100644 --- a/flepimop/gempyor_pkg/src/gempyor/model_info.py +++ b/flepimop/gempyor_pkg/src/gempyor/model_info.py @@ -19,7 +19,7 @@ def __init__(self, config: confuse.ConfigView): self.tf = config["end_date"].as_date() if self.tf <= self.ti: raise ValueError( - "`tf` (time to finish) is less than or equal to `ti` (time to start)." + f"Time to finish ('{self.tf}') is less than or equal to ('{self.ti}')." ) self.n_days = (self.tf - self.ti).days + 1 self.dates = pd.date_range(start=self.ti, end=self.tf, freq="D") @@ -76,8 +76,7 @@ def __init__( # Auto-detect old config if config["interventions"].exists(): raise ValueError( - "This config has an intervention section, which is only compatible with a previous version of flepiMoP/COVIDScenarioPipeline. " - "Please use flepiMoP Version 1.1 to run this config." + "This config has an intervention section, which is only compatible with a previous version (1.1) of flepiMoP." ) # 1. Create a setup name that contains every scenario. @@ -168,19 +167,19 @@ def __init__( self.seir_modifiers_library = config["seir_modifiers"][ "modifiers" ].get() - raise ValueError( + raise NotImplementedError( "This feature has not been implemented yet." ) # TODO create a Stacked from all elif self.seir_modifiers_scenario is not None: raise ValueError( - "A seir modifiers scenario was provided to `ModelInfo` but there is no `seir_modifiers` sections in config." + "A seir modifiers scenario was provided to `ModelInfo` but there is no `seir_modifiers` section in the config." ) else: logging.info("Running `ModelInfo` with seir but without SEIR Modifiers") elif self.seir_modifiers_scenario is not None: raise ValueError( - "A seir modifiers scenario was provided to `ModelInfo` but there is no `seir_modifiers` sections in config." + "A seir modifiers scenario was provided to `ModelInfo` but there is no `seir_modifiers` section in the config." ) else: logging.critical("Running ModelInfo without SEIR") @@ -201,7 +200,7 @@ def __init__( self.outcome_modifiers_library = config["outcome_modifiers"][ "modifiers" ].get() - raise ValueError( + raise NotImplementedError( "This feature has not been implemented yet." ) # TODO create a Stacked from all @@ -209,7 +208,7 @@ def __init__( elif self.outcome_modifiers_scenario is not None: if config["outcome_modifiers"].exists(): raise ValueError( - "An outcome modifiers scenario was provided to `ModelInfo` but there is no `outcome_modifiers` sections in config." + "An outcome modifiers scenario was provided to `ModelInfo` but there is no `outcome_modifiers` section in the config." ) else: self.outcome_modifiers_scenario = None @@ -219,10 +218,10 @@ def __init__( ) elif self.outcome_modifiers_scenario is not None: raise ValueError( - "An outcome modifiers scenario was provided to `ModelInfo` but there is no `outcome_modifiers` sections in config." + "An outcome modifiers scenario was provided to `ModelInfo` but there is no `outcome_modifiers` section in the config." ) else: - logging.info("Running `ModelInfo` without Outcomes") + logging.info("Running `ModelInfo` without outcomes.") # 6. Inputs and outputs if in_run_id is None: diff --git a/flepimop/gempyor_pkg/src/gempyor/outcomes.py b/flepimop/gempyor_pkg/src/gempyor/outcomes.py index aeb7e0032..7141d0c58 100644 --- a/flepimop/gempyor_pkg/src/gempyor/outcomes.py +++ b/flepimop/gempyor_pkg/src/gempyor/outcomes.py @@ -184,9 +184,8 @@ def read_parameters_from_config(modinf: model_info.ModelInfo): else: raise ValueError( - f"Unable to read outcome '{new_comp}': " - f"expected a string or dictionary containing `incidence` or `prevalence`. " - f"Recieved: '{src_name}'." + f"Expected a `str` or `dict` containing `incidence` or `prevalence`. " + f"Instead given '{src_name}' for outcome '{new_comp}'." ) parameters[new_comp]["probability"] = outcomes_config[new_comp][ @@ -671,7 +670,7 @@ def multishiftee(arr, shifts, stoch_delay_flag=True): result = np.zeros_like(arr) if stoch_delay_flag: - raise ValueError("`stoch_delay_flag` not supported yet.") + raise NotImplementedError("`stoch_delay_flag` not supported yet.") # for i, row in reversed(enumerate(np.rows(arr))): # for j,elem in reversed(enumerate(row)): ## This function takes in : @@ -697,7 +696,7 @@ def multishift(arr, shifts, stoch_delay_flag=True): result = np.zeros_like(arr) if stoch_delay_flag: - raise ValueError("`stoch_delay_flag` not supported yet.") + raise NotImplementedError("`stoch_delay_flag` not supported yet.") # for i, row in reversed(enumerate(np.rows(arr))): # for j,elem in reversed(enumerate(row)): ## This function takes in : diff --git a/flepimop/gempyor_pkg/src/gempyor/seeding.py b/flepimop/gempyor_pkg/src/gempyor/seeding.py index 5d0653d0e..e86f598c9 100644 --- a/flepimop/gempyor_pkg/src/gempyor/seeding.py +++ b/flepimop/gempyor_pkg/src/gempyor/seeding.py @@ -17,7 +17,7 @@ def _DataFrame2NumbaDict(df, amounts, modinf) -> nb.typed.Dict: if not df["date"].is_monotonic_increasing: - raise ValueError("`_DataFrame2NumbaDict` got an unsorted dataframe.") + raise ValueError("The `df` given is not sorted by the 'date' column.") cmp_grp_names = [ col for col in modinf.compartments.compartments.columns if col != "name" @@ -134,7 +134,7 @@ def get_from_config(self, sim_id: int, modinf) -> nb.typed.Dict: seeding = pd.DataFrame(columns=["date", "subpop"]) return _DataFrame2NumbaDict(df=seeding, amounts=[], modinf=modinf) else: - raise NotImplementedError(f"Unknown seeding method [received: '{method}'].") + raise ValueError(f"Unknown seeding method [received: '{method}'].") # Sorting by date is very important here for the seeding format necessary !!!! # print(seeding.shape) diff --git a/flepimop/gempyor_pkg/src/gempyor/statistics.py b/flepimop/gempyor_pkg/src/gempyor/statistics.py index ea10e7aa1..3208a6569 100644 --- a/flepimop/gempyor_pkg/src/gempyor/statistics.py +++ b/flepimop/gempyor_pkg/src/gempyor/statistics.py @@ -74,7 +74,10 @@ def __init__(self, name: str, statistic_config: confuse.ConfigView) -> None: reg_name = reg_config["name"].get() reg_func = getattr(self, f"_{reg_name}_regularize", None) if reg_func is None: - raise ValueError(f"Unsupported regularization: {reg_name}") + raise ValueError( + f"Unsupported regularization [received: '{reg_name}']. " + f"Currently only `forecast` and `allsubpop` are supported." + ) self.regularizations.append((reg_func, reg_config.get())) self.resample = False @@ -253,7 +256,10 @@ def llik(self, model_data: xr.DataArray, gt_data: xr.DataArray) -> xr.DataArray: "absolute_error": lambda x, y: -np.log(np.nansum(np.abs(x - y))), } if self.dist not in dist_map: - raise ValueError(f"Invalid distribution specified: {self.dist}") + raise ValueError( + f"Invalid distribution specified [received: '{self.dist}']. " + f"Valid distributions: '{dist_map}'." + ) if self.dist in ["pois", "nbinom"]: model_data = model_data.astype(int) gt_data = gt_data.astype(int) @@ -295,11 +301,9 @@ def compute_logloss( if not model_data.shape == gt_data.shape: raise ValueError( - ( - f"{self.name} Statistic error: data and groundtruth do not have " - f"the same shape: model_data.shape={model_data.shape} != " - f"gt_data.shape={gt_data.shape}" - ) + f"`model_data` and `gt_data` do not have " + f"the same shape: `model_data.shape` = '{model_data.shape}' != " + f"`gt_data.shape` = '{gt_data.shape}'." ) regularization = 0.0 diff --git a/flepimop/gempyor_pkg/src/gempyor/utils.py b/flepimop/gempyor_pkg/src/gempyor/utils.py index 377dcdee5..7df96d1f4 100644 --- a/flepimop/gempyor_pkg/src/gempyor/utils.py +++ b/flepimop/gempyor_pkg/src/gempyor/utils.py @@ -47,7 +47,7 @@ def write_df( None Raises: - NotImplementedError: The given output extension is not supported yet. + ValueError: The given output extension is not supported yet. """ # Decipher the path given fname = fname.decode() if isinstance(fname, bytes) else fname @@ -57,8 +57,8 @@ def write_df( return df.to_csv(path, index=False) elif path.suffix == ".parquet": return df.to_parquet(path, index=False, engine="pyarrow") - raise NotImplementedError( - f"Invalid extension {path.suffix[1:]}. Must be 'csv' or 'parquet'." + raise ValueError( + f"Invalid extension provided: '{path.suffix[1:]}'. Supported extensions are `.csv` or `.parquet`." ) @@ -82,7 +82,7 @@ def read_df( A pandas DataFrame parsed from the file given. Raises: - NotImplementedError: The given output extension is not supported yet. + ValueError: The given output extension is not supported yet. """ # Decipher the path given fname = fname.decode() if isinstance(fname, bytes) else fname @@ -94,8 +94,8 @@ def read_df( ) elif path.suffix == ".parquet": return pd.read_parquet(path, engine="pyarrow") - raise NotImplementedError( - f"Invalid extension {path.suffix[1:]}. Must be 'csv' or 'parquet'." + raise ValueError( + f"Invalid extension provided: '{path.suffix[1:]}'. Supported extensions are `.csv` or `.parquet`." ) @@ -114,7 +114,7 @@ def command_safe_run( As a tuple; the return code, the standard output, and standard error from running the command. Raises: - Exception: If fail_on_fail=True and the command fails, an exception will be thrown. + RuntimeError: If fail_on_fail=True and the command fails, an error will be thrown. """ import subprocess import shlex # using shlex to split the command because it's not obvious https://docs.python.org/3/library/subprocess.html#subprocess.Popen @@ -124,8 +124,8 @@ def command_safe_run( ) (stdout, stderr) = sr.communicate() if sr.returncode != 0: - print(f"{command_name} failed failed with returncode {sr.returncode}") - print(f"{command_name}: {command}") + print(f"'{command_name}' failed failed with returncode '{sr.returncode}'") + print(f"'{command_name}': '{command}'") print("{command_name} command failed with stdout and stderr:") print("{command_name} stdout >>>>>>") @@ -136,7 +136,7 @@ def command_safe_run( print(stderr.decode()) print("{command_name} stderr <<<<<<") if fail_on_fail: - raise Exception(f"{command_name} command failed") + raise RuntimeError(f"The '{command_name}' command failed.") return sr.returncode, stdout, stderr @@ -362,7 +362,7 @@ def as_evaled_expression(self): except TypeError as e: raise ValueError(e) from e else: - raise ValueError(f"expected numeric or string expression [got: {value}]") + raise ValueError(f"Expected numeric or string expression [received: '{value}'].") def get_truncated_normal( @@ -484,7 +484,7 @@ def random_distribution_sampler( elif distribution == "binomial": p = kwargs.get("p") if not (0 < p < 1): - raise ValueError(f"p value {p} is out of range [0,1]") + raise ValueError(f"Invalid `p-value`: '{p}' is out of range [0,1].") return functools.partial(np.random.binomial, kwargs.get("n"), p) elif distribution == "truncnorm": # Truncated normal with mean, sd on interval [a, b] @@ -497,7 +497,7 @@ def random_distribution_sampler( elif distribution == "lognorm": # Lognormal distribution with meanlog, sdlog return get_log_normal(kwargs.get("meanlog"), kwargs.get("sdlog")).rvs - raise NotImplementedError(f"unknown distribution [got: {distribution}]") + raise NotImplementedError(f"Unkown distribution [received: '{distribution}'].") @add_method(confuse.ConfigView) @@ -556,7 +556,7 @@ def as_random_distribution(self): elif dist == "binomial": p = self["p"].as_evaled_expression() if (p < 0) or (p > 1): - raise ValueError(f"""p value { p } is out of range [0,1]""") + raise ValueError(f"Invalid `p-value`: '{p}' is out of range [0,1].") # if (self["p"] < 0) or (self["p"] > 1): # raise ValueError(f"""p value { self["p"] } is out of range [0,1]""") return functools.partial( @@ -578,7 +578,7 @@ def as_random_distribution(self): sdlog=self["sdlog"].as_evaled_expression(), ).rvs else: - raise NotImplementedError(f"unknown distribution [got: {dist}]") + raise NotImplementedError(f"Unkown distribution [received: '{dist}'].") else: # we allow a fixed value specified directly: return functools.partial( @@ -716,13 +716,13 @@ def bash(command: str) -> str: f"shutil.disk_usage: {total_bytes/ 1000000} Mb total, {used_bytes / 1000000} Mb used, {free_bytes / 1000000} Mb free..." ) print("------------") - print(f"df -hT: {bash('df -hT')}") + print(f"df -hT: '{bash('df -hT')}'") print("------------") - print(f"df -i: {bash('df -i')}") + print(f"df -i: '{bash('df -i')}'") print("------------") - print(f"free -h: {bash('free -h')}") + print(f"free -h: '{bash('free -h')}'") print("------------") - print(f"lsblk: {bash('lsblk')}") + print(f"lsblk: '{bash('lsblk')}'") print("END AWS DIAGNOSIS ================================") @@ -1004,8 +1004,8 @@ def download_file_from_s3(name_map: dict[str, str]) -> None: except ModuleNotFoundError: raise ModuleNotFoundError( ( - "No module named 'boto3', which is required for " - "gempyor.utils.download_file_from_s3. Please install the aws target." + "No module named `boto3` found, which is required for " + "`gempyor.utils.download_file_from_s3`. Please install the aws target." ) ) s3 = boto3.client("s3") @@ -1020,10 +1020,9 @@ def download_file_from_s3(name_map: dict[str, str]) -> None: object = s3_uri[len(bucket) + 6 :] s3.download_file(bucket, object, name_map[s3_uri]) else: - raise ValueError(f"Invalid S3 URI format {s3_uri}") + raise ValueError(f"Invalid S3 URI format [received: '{s3_uri}'].") except ClientError as e: - print(f"An error occurred: {e}") - print("Could not download file from s3") + raise Exception(f"'{e}': could not download filefrom S3.") def move_file_at_local(name_map: dict[str, str]) -> None: diff --git a/flepimop/gempyor_pkg/tests/seir/test_seir.py b/flepimop/gempyor_pkg/tests/seir/test_seir.py index 8b772a689..b14767115 100644 --- a/flepimop/gempyor_pkg/tests/seir/test_seir.py +++ b/flepimop/gempyor_pkg/tests/seir/test_seir.py @@ -128,7 +128,7 @@ def test_constant_population_legacy_integration(): def test_constant_population_rk4jit_integration_fail(): - with pytest.raises(ValueError, match=r".*With.*method.*integration.*"): + with pytest.raises(ValueError, match=r".*integration method only supports deterministic integration.*"): config.set_file(f"{DATA_DIR}/config.yml") first_sim_index = 1 From b32c64e392e15deb675543026be3554979dc768b Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Wed, 13 Nov 2024 12:13:48 -0500 Subject: [PATCH 08/56] Regex adjustment --- flepimop/gempyor_pkg/src/gempyor/model_info.py | 2 +- flepimop/gempyor_pkg/tests/seir/test_model_info.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/flepimop/gempyor_pkg/src/gempyor/model_info.py b/flepimop/gempyor_pkg/src/gempyor/model_info.py index f22e16d1d..82956dd9e 100644 --- a/flepimop/gempyor_pkg/src/gempyor/model_info.py +++ b/flepimop/gempyor_pkg/src/gempyor/model_info.py @@ -19,7 +19,7 @@ def __init__(self, config: confuse.ConfigView): self.tf = config["end_date"].as_date() if self.tf <= self.ti: raise ValueError( - f"Time to finish ('{self.tf}') is less than or equal to ('{self.ti}')." + f"Time to finish ('{self.tf}') is less than or equal to time to start ('{self.ti}')." ) self.n_days = (self.tf - self.ti).days + 1 self.dates = pd.date_range(start=self.ti, end=self.tf, freq="D") diff --git a/flepimop/gempyor_pkg/tests/seir/test_model_info.py b/flepimop/gempyor_pkg/tests/seir/test_model_info.py index 4790063eb..81cf69492 100644 --- a/flepimop/gempyor_pkg/tests/seir/test_model_info.py +++ b/flepimop/gempyor_pkg/tests/seir/test_model_info.py @@ -46,7 +46,7 @@ def test_ModelInfo_init_tf_is_ahead_of_ti_fail(self): config["start_date"] = "2022-01-02" with pytest.raises( ValueError, - match=r"`tf`\s?\(time to finish\)\s?is less than or equal to\s?`ti`\s?\(time to start\)\.", + match=r"Time to finish \('\{self\.tf\}'\) is less than or equal to time to start \('\{self\.ti\}'\)\.", ): s = ModelInfo( config=config, From d844ced1d806e8047f4ad3a2b94d294c4186b00f Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Wed, 13 Nov 2024 12:24:53 -0500 Subject: [PATCH 09/56] Regex update --- flepimop/gempyor_pkg/tests/seir/test_model_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/seir/test_model_info.py b/flepimop/gempyor_pkg/tests/seir/test_model_info.py index 81cf69492..baad036b4 100644 --- a/flepimop/gempyor_pkg/tests/seir/test_model_info.py +++ b/flepimop/gempyor_pkg/tests/seir/test_model_info.py @@ -46,7 +46,7 @@ def test_ModelInfo_init_tf_is_ahead_of_ti_fail(self): config["start_date"] = "2022-01-02" with pytest.raises( ValueError, - match=r"Time to finish \('\{self\.tf\}'\) is less than or equal to time to start \('\{self\.ti\}'\)\.", + match=r"Time to finish.*is less than or equal to time to start.*", ): s = ModelInfo( config=config, From 2cbf2ed375ce464c3e375c7bf5a7dba92e20d68e Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Wed, 13 Nov 2024 16:06:51 -0500 Subject: [PATCH 10/56] Implementing Tim's suggestions --- flepimop/gempyor_pkg/src/gempyor/seeding.py | 4 ++-- flepimop/gempyor_pkg/src/gempyor/seir.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/flepimop/gempyor_pkg/src/gempyor/seeding.py b/flepimop/gempyor_pkg/src/gempyor/seeding.py index e86f598c9..c341ed93c 100644 --- a/flepimop/gempyor_pkg/src/gempyor/seeding.py +++ b/flepimop/gempyor_pkg/src/gempyor/seeding.py @@ -134,7 +134,7 @@ def get_from_config(self, sim_id: int, modinf) -> nb.typed.Dict: seeding = pd.DataFrame(columns=["date", "subpop"]) return _DataFrame2NumbaDict(df=seeding, amounts=[], modinf=modinf) else: - raise ValueError(f"Unknown seeding method [received: '{method}'].") + raise ValueError(f"Unknown seeding method given, '{method}'.") # Sorting by date is very important here for the seeding format necessary !!!! # print(seeding.shape) @@ -159,7 +159,7 @@ def get_from_config(self, sim_id: int, modinf) -> nb.typed.Dict: elif method == "FolderDraw" or method == "FromFile": amounts = seeding["amount"] else: - raise ValueError(f"Unknown seeding method [received: '{method}'].") + raise ValueError(f"Unknown seeding method given, '{method}'.") return _DataFrame2NumbaDict(df=seeding, amounts=amounts, modinf=modinf) diff --git a/flepimop/gempyor_pkg/src/gempyor/seir.py b/flepimop/gempyor_pkg/src/gempyor/seir.py index da62c9101..7bbf6995c 100644 --- a/flepimop/gempyor_pkg/src/gempyor/seir.py +++ b/flepimop/gempyor_pkg/src/gempyor/seir.py @@ -32,7 +32,7 @@ def build_step_source_arg( integration_method = "rk4.jit" if integration_method not in ["rk4.jit", "legacy"]: raise ValueError( - f"Unknown integration method [received: '{integration_method}']." + f"Unknown integration method given, '{integration_method}'." ) if "dt" in modinf.seir_config["integration"].keys(): dt = float( @@ -188,7 +188,7 @@ def steps_SEIR( seir_sim = steps_experimental.rk4_aot(**fnct_args) else: raise ValueError( - f"Unknown integration method [received '{integration_method}']." + f"Unknown integration method given, '{integration_method}'." ) # We return an xarray instead of a ndarray now From a1692a159e09ab44602a37f5f839fed286b85f17 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Mon, 18 Nov 2024 13:03:19 -0500 Subject: [PATCH 11/56] Regex update in test_statistic_class.py --- flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py b/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py index 4843986c1..614a63d67 100644 --- a/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py +++ b/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py @@ -249,7 +249,7 @@ def test_unsupported_regularizations_value_error( if reg_name not in ["forecast", "allsubpop"] ) with pytest.raises( - ValueError, match=rf"^Unsupported regularization\: {unsupported_name}$" + ValueError, match=r"^Unsupported regularization \[received:.*$" ): mock_inputs.create_statistic_instance() From 759795fdeeb282ec892c06ec8cc578df31a39f85 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Mon, 18 Nov 2024 13:17:13 -0500 Subject: [PATCH 12/56] Regex update in `test_statistic_class.py` --- flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py b/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py index 614a63d67..d9d4270e4 100644 --- a/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py +++ b/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py @@ -523,9 +523,7 @@ def test_compute_logloss_data_misshape_value_error( model_rows, model_cols = mock_inputs.model_data[mock_inputs.config["sim_var"]].shape gt_rows, gt_cols = mock_inputs.gt_data[mock_inputs.config["data_var"]].shape expected_match = ( - rf"^{mock_inputs.name} Statistic error\: data and groundtruth do not have " - rf"the same shape\: model\_data\.shape\=\({model_rows}\, {model_cols}\) " - rf"\!\= gt\_data\.shape\=\({gt_rows}\, {gt_cols}\)$" + rf".*do not have the same shape:.*" ) with pytest.raises(ValueError, match=expected_match): statistic.compute_logloss(mock_inputs.model_data, mock_inputs.gt_data) From df784d59d86277a1574a5d70dceb0765ab55342d Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Mon, 18 Nov 2024 15:19:11 -0500 Subject: [PATCH 13/56] Regex adjusment in `test_random_distribution_sampler.py` --- flepimop/gempyor_pkg/src/gempyor/utils.py | 2 +- .../gempyor_pkg/tests/utils/test_random_distribution_sampler.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/flepimop/gempyor_pkg/src/gempyor/utils.py b/flepimop/gempyor_pkg/src/gempyor/utils.py index 7df96d1f4..8ad0d940e 100644 --- a/flepimop/gempyor_pkg/src/gempyor/utils.py +++ b/flepimop/gempyor_pkg/src/gempyor/utils.py @@ -578,7 +578,7 @@ def as_random_distribution(self): sdlog=self["sdlog"].as_evaled_expression(), ).rvs else: - raise NotImplementedError(f"Unkown distribution [received: '{dist}'].") + raise NotImplementedError(f"Unknown distribution [received: '{dist}'].") else: # we allow a fixed value specified directly: return functools.partial( diff --git a/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py b/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py index 4ca9c0ac7..41846a632 100644 --- a/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py +++ b/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py @@ -14,7 +14,7 @@ class TestRandomDistributionSampler: def test_not_implemented_error_exception(self, distribution: str) -> None: with pytest.raises( NotImplementedError, - match=rf"^unknown distribution \[got\: {distribution}\]$", + match=rf"^Unknown distribution \[received.*", ): random_distribution_sampler(distribution) From 8ec6c0578b9ffc36cfd82d67b0abfe817df2689f Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Mon, 18 Nov 2024 15:42:51 -0500 Subject: [PATCH 14/56] Fixing typo in `utils.py` --- flepimop/gempyor_pkg/src/gempyor/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/src/gempyor/utils.py b/flepimop/gempyor_pkg/src/gempyor/utils.py index 8ad0d940e..8c76ffb5e 100644 --- a/flepimop/gempyor_pkg/src/gempyor/utils.py +++ b/flepimop/gempyor_pkg/src/gempyor/utils.py @@ -497,7 +497,7 @@ def random_distribution_sampler( elif distribution == "lognorm": # Lognormal distribution with meanlog, sdlog return get_log_normal(kwargs.get("meanlog"), kwargs.get("sdlog")).rvs - raise NotImplementedError(f"Unkown distribution [received: '{distribution}'].") + raise NotImplementedError(f"Unknown distribution [received: '{distribution}'].") @add_method(confuse.ConfigView) From d760ddc8ed821e0da0c232240fe1a14205b38852 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Mon, 18 Nov 2024 16:27:07 -0500 Subject: [PATCH 15/56] Regex update in `test_random_distribution_sampler.py` --- .../gempyor_pkg/tests/utils/test_random_distribution_sampler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py b/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py index 41846a632..5283babbc 100644 --- a/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py +++ b/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py @@ -22,7 +22,7 @@ def test_not_implemented_error_exception(self, distribution: str) -> None: def test_binomial_p_value_error(self, p: float) -> None: with pytest.raises( ValueError, - match=rf"^p value {p} is out of range \[0\,1\]$", + match=r"^Invalid\s`p-value`.*\s'is\sout\sof\srange.*'", ): random_distribution_sampler("binomial", n=100, p=p) From 7e19700eb57302ee527d012422c5edf191a82237 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Mon, 18 Nov 2024 16:53:58 -0500 Subject: [PATCH 16/56] Regex update in `test_random_distribution_sampler.py` --- .../gempyor_pkg/tests/utils/test_random_distribution_sampler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py b/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py index 5283babbc..596d296c1 100644 --- a/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py +++ b/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py @@ -22,7 +22,7 @@ def test_not_implemented_error_exception(self, distribution: str) -> None: def test_binomial_p_value_error(self, p: float) -> None: with pytest.raises( ValueError, - match=r"^Invalid\s`p-value`.*\s'is\sout\sof\srange.*'", + match=r"^Invalid\s`p-value`.*\sis\sout\sof\srange.*$", ): random_distribution_sampler("binomial", n=100, p=p) From 452ddbbdba62481eb79c40aac0bca7aa5aa8250d Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Wed, 20 Nov 2024 10:16:06 -0500 Subject: [PATCH 17/56] Update utils.py the function `test_raises_not_implemented_error()` in test file `test_read_df.py` on account that it was receiving a `ValueError` when it expected a `NotImplementedError`. I switched the error within `utils.py:read_df()` to be an expected `NotImplementedError`. --- flepimop/gempyor_pkg/src/gempyor/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/src/gempyor/utils.py b/flepimop/gempyor_pkg/src/gempyor/utils.py index 8c76ffb5e..397bd0909 100644 --- a/flepimop/gempyor_pkg/src/gempyor/utils.py +++ b/flepimop/gempyor_pkg/src/gempyor/utils.py @@ -94,7 +94,7 @@ def read_df( ) elif path.suffix == ".parquet": return pd.read_parquet(path, engine="pyarrow") - raise ValueError( + raise NotImplementedError( f"Invalid extension provided: '{path.suffix[1:]}'. Supported extensions are `.csv` or `.parquet`." ) From 99d2f36cc1976b9d3c4da194f2b02c9aad234baf Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Wed, 20 Nov 2024 10:42:51 -0500 Subject: [PATCH 18/56] Regex update in `test_read_df.py` --- flepimop/gempyor_pkg/tests/utils/test_read_df.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flepimop/gempyor_pkg/tests/utils/test_read_df.py b/flepimop/gempyor_pkg/tests/utils/test_read_df.py index 48f05dbd5..34d05708a 100644 --- a/flepimop/gempyor_pkg/tests/utils/test_read_df.py +++ b/flepimop/gempyor_pkg/tests/utils/test_read_df.py @@ -38,13 +38,13 @@ def test_raises_not_implemented_error(self) -> None: """ with pytest.raises( expected_exception=NotImplementedError, - match="Invalid extension txt. Must be 'csv' or 'parquet'.", + match=".*Supported extensions are \.`csv`\s+or\s+\.`parquet`\.", ) as _: with NamedTemporaryFile(suffix=".txt") as temp_file: read_df(fname=temp_file.name) with pytest.raises( expected_exception=NotImplementedError, - match="Invalid extension txt. Must be 'csv' or 'parquet'.", + match=".*Supported extensions are \.`csv`\s+or\s+\.`parquet`\.", ) as _: with NamedTemporaryFile(suffix=".txt") as temp_file: fname = temp_file.name[:-4] From 47514d574e9d96dcb34df2315b87b95629c9feea Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Wed, 20 Nov 2024 11:10:06 -0500 Subject: [PATCH 19/56] Regex update in `test_read_df.py` --- flepimop/gempyor_pkg/tests/utils/test_read_df.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flepimop/gempyor_pkg/tests/utils/test_read_df.py b/flepimop/gempyor_pkg/tests/utils/test_read_df.py index 34d05708a..48ac4e770 100644 --- a/flepimop/gempyor_pkg/tests/utils/test_read_df.py +++ b/flepimop/gempyor_pkg/tests/utils/test_read_df.py @@ -38,13 +38,13 @@ def test_raises_not_implemented_error(self) -> None: """ with pytest.raises( expected_exception=NotImplementedError, - match=".*Supported extensions are \.`csv`\s+or\s+\.`parquet`\.", + match=r".*Supported extensions are \.`csv`\s+or\s+\.`parquet`\.", ) as _: with NamedTemporaryFile(suffix=".txt") as temp_file: read_df(fname=temp_file.name) with pytest.raises( expected_exception=NotImplementedError, - match=".*Supported extensions are \.`csv`\s+or\s+\.`parquet`\.", + match=r".*Supported extensions are \.`csv`\s+or\s+\.`parquet`\.", ) as _: with NamedTemporaryFile(suffix=".txt") as temp_file: fname = temp_file.name[:-4] From 97d39960ffca3244bf2238ae2af39840c1df6bb1 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Wed, 20 Nov 2024 11:45:45 -0500 Subject: [PATCH 20/56] Regex update in `test_read_df.py` --- flepimop/gempyor_pkg/tests/utils/test_read_df.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flepimop/gempyor_pkg/tests/utils/test_read_df.py b/flepimop/gempyor_pkg/tests/utils/test_read_df.py index 48ac4e770..676f5d699 100644 --- a/flepimop/gempyor_pkg/tests/utils/test_read_df.py +++ b/flepimop/gempyor_pkg/tests/utils/test_read_df.py @@ -38,13 +38,13 @@ def test_raises_not_implemented_error(self) -> None: """ with pytest.raises( expected_exception=NotImplementedError, - match=r".*Supported extensions are \.`csv`\s+or\s+\.`parquet`\.", + match=r".*Supported extensions are `.csv` or `.parquet`.", ) as _: with NamedTemporaryFile(suffix=".txt") as temp_file: read_df(fname=temp_file.name) with pytest.raises( expected_exception=NotImplementedError, - match=r".*Supported extensions are \.`csv`\s+or\s+\.`parquet`\.", + match=r".*Supported extensions are `.csv` or `.parquet`.", ) as _: with NamedTemporaryFile(suffix=".txt") as temp_file: fname = temp_file.name[:-4] From 918ebc793032f796cc0ec8affe02c79d1ec0ea6b Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Wed, 20 Nov 2024 11:57:12 -0500 Subject: [PATCH 21/56] Updating a unit test in `test_utils.py` --- flepimop/gempyor_pkg/tests/utils/test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/utils/test_utils.py b/flepimop/gempyor_pkg/tests/utils/test_utils.py index 87e7c4fbb..5a434d299 100644 --- a/flepimop/gempyor_pkg/tests/utils/test_utils.py +++ b/flepimop/gempyor_pkg/tests/utils/test_utils.py @@ -37,7 +37,7 @@ def test_read_df_and_write_success(fname, extension): ("fname", "extension"), [("mobility", "csv"), ("usa-geoid-params-output", "parquet")] ) def test_read_df_and_write_fail(fname, extension): - with pytest.raises(NotImplementedError, match=r".*Invalid.*extension.*Must.*"): + with pytest.raises(ValueError, match=r".*Invalid.*extension.*Must.*"): os.chdir(tmp_path) os.makedirs("data", exist_ok=True) os.chdir("data") From 764c4b2c73c2a02e57b2ac902acbd4297f3f6845 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Wed, 20 Nov 2024 12:07:45 -0500 Subject: [PATCH 22/56] Regex update in `test_utils.py` and error type agreement with `utils.py` --- flepimop/gempyor_pkg/src/gempyor/utils.py | 2 +- flepimop/gempyor_pkg/tests/utils/test_utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/flepimop/gempyor_pkg/src/gempyor/utils.py b/flepimop/gempyor_pkg/src/gempyor/utils.py index 397bd0909..5178d19a9 100644 --- a/flepimop/gempyor_pkg/src/gempyor/utils.py +++ b/flepimop/gempyor_pkg/src/gempyor/utils.py @@ -57,7 +57,7 @@ def write_df( return df.to_csv(path, index=False) elif path.suffix == ".parquet": return df.to_parquet(path, index=False, engine="pyarrow") - raise ValueError( + raise NotImplementedError( f"Invalid extension provided: '{path.suffix[1:]}'. Supported extensions are `.csv` or `.parquet`." ) diff --git a/flepimop/gempyor_pkg/tests/utils/test_utils.py b/flepimop/gempyor_pkg/tests/utils/test_utils.py index 5a434d299..942d79588 100644 --- a/flepimop/gempyor_pkg/tests/utils/test_utils.py +++ b/flepimop/gempyor_pkg/tests/utils/test_utils.py @@ -37,7 +37,7 @@ def test_read_df_and_write_success(fname, extension): ("fname", "extension"), [("mobility", "csv"), ("usa-geoid-params-output", "parquet")] ) def test_read_df_and_write_fail(fname, extension): - with pytest.raises(ValueError, match=r".*Invalid.*extension.*Must.*"): + with pytest.raises(NotImplementedError, match=r".*Supported extensions are `.csv` or `.parquet`."): os.chdir(tmp_path) os.makedirs("data", exist_ok=True) os.chdir("data") From c1e79c2c0ed24f6b3cf9e79d311f4e7570660493 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Wed, 20 Nov 2024 12:16:30 -0500 Subject: [PATCH 23/56] Regex update in `test_write_df.py` --- flepimop/gempyor_pkg/tests/utils/test_write_df.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/utils/test_write_df.py b/flepimop/gempyor_pkg/tests/utils/test_write_df.py index b13e0b948..314c24152 100644 --- a/flepimop/gempyor_pkg/tests/utils/test_write_df.py +++ b/flepimop/gempyor_pkg/tests/utils/test_write_df.py @@ -30,7 +30,7 @@ def test_raises_not_implemented_error(self) -> None: """ with pytest.raises( expected_exception=NotImplementedError, - match="Invalid extension txt. Must be 'csv' or 'parquet'.", + match=r".*Supported extensions are `.csv` or `.parquet`.", ) as _: with NamedTemporaryFile(suffix=".txt") as temp_file: write_df(fname=temp_file.name, df=self.sample_df) From 4fd1b116f40d776988cbe3c667700c9d53a83ab9 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Wed, 20 Nov 2024 12:23:50 -0500 Subject: [PATCH 24/56] Regex update in `test-write_df.py` --- flepimop/gempyor_pkg/tests/utils/test_write_df.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/utils/test_write_df.py b/flepimop/gempyor_pkg/tests/utils/test_write_df.py index 314c24152..8f4e18baf 100644 --- a/flepimop/gempyor_pkg/tests/utils/test_write_df.py +++ b/flepimop/gempyor_pkg/tests/utils/test_write_df.py @@ -36,7 +36,7 @@ def test_raises_not_implemented_error(self) -> None: write_df(fname=temp_file.name, df=self.sample_df) with pytest.raises( expected_exception=NotImplementedError, - match="Invalid extension txt. Must be 'csv' or 'parquet'.", + match=r".*Supported extensions are `.csv` or `.parquet`.", ) as _: with NamedTemporaryFile(suffix=".txt") as temp_file: fname = temp_file.name[:-4] From 2e62ae35147ab85e2b7c723fb2fc2cb6156b51b7 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Wed, 20 Nov 2024 12:37:45 -0500 Subject: [PATCH 25/56] Removing deprecated style of `\` to escape colons --- flepimop/gempyor_pkg/tests/parameters/test_parameters_class.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/parameters/test_parameters_class.py b/flepimop/gempyor_pkg/tests/parameters/test_parameters_class.py index f82cf2a27..9801a6193 100644 --- a/flepimop/gempyor_pkg/tests/parameters/test_parameters_class.py +++ b/flepimop/gempyor_pkg/tests/parameters/test_parameters_class.py @@ -283,7 +283,7 @@ def test_timeseries_parameter_has_insufficient_dates_value_error( ValueError, match=( f"Issue loading file '{tmp_file}' for parameter 'sigma': " - f"Provided file dates span '{timeseries_start_date}( 00\:00\:00)?' to '{timeseries_end_date}( 00\:00\:00)?', " + f"Provided file dates span '{timeseries_start_date}( 00:00:00)?' to '{timeseries_end_date}( 00:00:00)?', " f"but the config dates span '{mock_inputs.ti}' to '{mock_inputs.tf}'.$" ), ): From e5772c79b242a2ff4f839313d0c2cec75191fac0 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Wed, 20 Nov 2024 12:56:03 -0500 Subject: [PATCH 26/56] linting with `black` --- flepimop/gempyor_pkg/src/gempyor/seir.py | 6 ++---- flepimop/gempyor_pkg/src/gempyor/statistics.py | 6 +++--- flepimop/gempyor_pkg/tests/seir/test_seir.py | 4 +++- .../gempyor_pkg/tests/statistics/test_statistic_class.py | 8 ++------ flepimop/gempyor_pkg/tests/utils/test_utils.py | 4 +++- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/flepimop/gempyor_pkg/src/gempyor/seir.py b/flepimop/gempyor_pkg/src/gempyor/seir.py index 7bbf6995c..b5742efad 100644 --- a/flepimop/gempyor_pkg/src/gempyor/seir.py +++ b/flepimop/gempyor_pkg/src/gempyor/seir.py @@ -165,7 +165,7 @@ def steps_SEIR( ]: if modinf.stoch_traj_flag == True: raise ValueError( - f"'{integration_method}' integration method only supports deterministic integration, but `stoch_straj_flag` is '{modinf.stoch_traj_flag}'." + f"'{integration_method}' integration method only supports deterministic integration, but `stoch_straj_flag` is '{modinf.stoch_traj_flag}'." ) seir_sim = steps_experimental.ode_integration( **fnct_args, integration_method=integration_method @@ -187,9 +187,7 @@ def steps_SEIR( elif integration_method == "rk4_aot": seir_sim = steps_experimental.rk4_aot(**fnct_args) else: - raise ValueError( - f"Unknown integration method given, '{integration_method}'." - ) + raise ValueError(f"Unknown integration method given, '{integration_method}'.") # We return an xarray instead of a ndarray now compartment_coords = {} diff --git a/flepimop/gempyor_pkg/src/gempyor/statistics.py b/flepimop/gempyor_pkg/src/gempyor/statistics.py index 3208a6569..b6ced5e6d 100644 --- a/flepimop/gempyor_pkg/src/gempyor/statistics.py +++ b/flepimop/gempyor_pkg/src/gempyor/statistics.py @@ -301,9 +301,9 @@ def compute_logloss( if not model_data.shape == gt_data.shape: raise ValueError( - f"`model_data` and `gt_data` do not have " - f"the same shape: `model_data.shape` = '{model_data.shape}' != " - f"`gt_data.shape` = '{gt_data.shape}'." + f"`model_data` and `gt_data` do not have " + f"the same shape: `model_data.shape` = '{model_data.shape}' != " + f"`gt_data.shape` = '{gt_data.shape}'." ) regularization = 0.0 diff --git a/flepimop/gempyor_pkg/tests/seir/test_seir.py b/flepimop/gempyor_pkg/tests/seir/test_seir.py index b14767115..9cf89032e 100644 --- a/flepimop/gempyor_pkg/tests/seir/test_seir.py +++ b/flepimop/gempyor_pkg/tests/seir/test_seir.py @@ -128,7 +128,9 @@ def test_constant_population_legacy_integration(): def test_constant_population_rk4jit_integration_fail(): - with pytest.raises(ValueError, match=r".*integration method only supports deterministic integration.*"): + with pytest.raises( + ValueError, match=r".*integration method only supports deterministic integration.*" + ): config.set_file(f"{DATA_DIR}/config.yml") first_sim_index = 1 diff --git a/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py b/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py index d9d4270e4..5ec48ba76 100644 --- a/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py +++ b/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py @@ -248,9 +248,7 @@ def test_unsupported_regularizations_value_error( ] if reg_name not in ["forecast", "allsubpop"] ) - with pytest.raises( - ValueError, match=r"^Unsupported regularization \[received:.*$" - ): + with pytest.raises(ValueError, match=r"^Unsupported regularization \[received:.*$"): mock_inputs.create_statistic_instance() @pytest.mark.parametrize("factory", all_valid_factories) @@ -522,9 +520,7 @@ def test_compute_logloss_data_misshape_value_error( model_rows, model_cols = mock_inputs.model_data[mock_inputs.config["sim_var"]].shape gt_rows, gt_cols = mock_inputs.gt_data[mock_inputs.config["data_var"]].shape - expected_match = ( - rf".*do not have the same shape:.*" - ) + expected_match = rf".*do not have the same shape:.*" with pytest.raises(ValueError, match=expected_match): statistic.compute_logloss(mock_inputs.model_data, mock_inputs.gt_data) diff --git a/flepimop/gempyor_pkg/tests/utils/test_utils.py b/flepimop/gempyor_pkg/tests/utils/test_utils.py index 942d79588..c57ac900e 100644 --- a/flepimop/gempyor_pkg/tests/utils/test_utils.py +++ b/flepimop/gempyor_pkg/tests/utils/test_utils.py @@ -37,7 +37,9 @@ def test_read_df_and_write_success(fname, extension): ("fname", "extension"), [("mobility", "csv"), ("usa-geoid-params-output", "parquet")] ) def test_read_df_and_write_fail(fname, extension): - with pytest.raises(NotImplementedError, match=r".*Supported extensions are `.csv` or `.parquet`."): + with pytest.raises( + NotImplementedError, match=r".*Supported extensions are `.csv` or `.parquet`." + ): os.chdir(tmp_path) os.makedirs("data", exist_ok=True) os.chdir("data") From 8fe918aea488736f89eaf378a9f2d768867d96ec Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Wed, 20 Nov 2024 13:14:35 -0500 Subject: [PATCH 27/56] Updating `steps_source.py` and `utils.py` There were not that many changes in the final batch of error improvements, so I went ahead and lumped them in with batch two. --- flepimop/gempyor_pkg/src/gempyor/steps_source.py | 7 +++++-- flepimop/gempyor_pkg/src/gempyor/utils.py | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/flepimop/gempyor_pkg/src/gempyor/steps_source.py b/flepimop/gempyor_pkg/src/gempyor/steps_source.py index ea6f7ad21..7da7c393d 100644 --- a/flepimop/gempyor_pkg/src/gempyor/steps_source.py +++ b/flepimop/gempyor_pkg/src/gempyor/steps_source.py @@ -278,8 +278,11 @@ def steps_SEIR_nb( print(" ", states_current[comp].max()) if (states_current.min() < 0) or (states_current.max() > 10**10): - print((states_current.min() < 0), (states_current.max() > 10**10)) - raise ValueError(f"Overflow error. Too small ?. Too large ?") + raise ValueError( + f"State values are outside the valid range. " + f"Minimum value: '{states_current.min()}', Maximum value: '{states_current.max()}'. " + f"Valid range is between 0 and {10**10}." + ) return states, states_daily_incid diff --git a/flepimop/gempyor_pkg/src/gempyor/utils.py b/flepimop/gempyor_pkg/src/gempyor/utils.py index 5178d19a9..a937b53b4 100644 --- a/flepimop/gempyor_pkg/src/gempyor/utils.py +++ b/flepimop/gempyor_pkg/src/gempyor/utils.py @@ -47,7 +47,7 @@ def write_df( None Raises: - ValueError: The given output extension is not supported yet. + NotImplementedError: The given output extension is not supported yet. """ # Decipher the path given fname = fname.decode() if isinstance(fname, bytes) else fname @@ -82,7 +82,7 @@ def read_df( A pandas DataFrame parsed from the file given. Raises: - ValueError: The given output extension is not supported yet. + NotImplementedError: The given output extension is not supported yet. """ # Decipher the path given fname = fname.decode() if isinstance(fname, bytes) else fname From f7e53a70b5f66e8b4be0b2b4eda67226c1a99d53 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Fri, 22 Nov 2024 14:35:06 -0500 Subject: [PATCH 28/56] Implementing Carl's suggestions Awaiting regex error kickback to adjust the test files. --- flepimop/gempyor_pkg/src/gempyor/model_info.py | 12 ++++++------ flepimop/gempyor_pkg/src/gempyor/seeding.py | 2 -- flepimop/gempyor_pkg/src/gempyor/statistics.py | 4 ++-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/flepimop/gempyor_pkg/src/gempyor/model_info.py b/flepimop/gempyor_pkg/src/gempyor/model_info.py index 82956dd9e..3ba989cf3 100644 --- a/flepimop/gempyor_pkg/src/gempyor/model_info.py +++ b/flepimop/gempyor_pkg/src/gempyor/model_info.py @@ -19,7 +19,7 @@ def __init__(self, config: confuse.ConfigView): self.tf = config["end_date"].as_date() if self.tf <= self.ti: raise ValueError( - f"Time to finish ('{self.tf}') is less than or equal to time to start ('{self.ti}')." + f"Final time ('{self.tf}') is less than or equal to initial time('{self.ti}')." ) self.n_days = (self.tf - self.ti).days + 1 self.dates = pd.date_range(start=self.ti, end=self.tf, freq="D") @@ -76,7 +76,7 @@ def __init__( # Auto-detect old config if config["interventions"].exists(): raise ValueError( - "This config has an intervention section, which is only compatible with a previous version (1.1) of flepiMoP." + "This config has an intervention section, which is only compatible with a previous version (v1.1) of flepiMoP. " ) # 1. Create a setup name that contains every scenario. @@ -172,14 +172,14 @@ def __init__( ) # TODO create a Stacked from all elif self.seir_modifiers_scenario is not None: raise ValueError( - "A seir modifiers scenario was provided to `ModelInfo` but there is no `seir_modifiers` section in the config." + "A `seir_modifiers_scenario` argument was provided to `ModelInfo` but there is no `seir_modifiers` section in the config." ) else: logging.info("Running `ModelInfo` with seir but without SEIR Modifiers") elif self.seir_modifiers_scenario is not None: raise ValueError( - "A seir modifiers scenario was provided to `ModelInfo` but there is no `seir_modifiers` section in the config." + "A `seir_modifiers_scenario` argument was provided to `ModelInfo` but there is no `seir` section in the config." ) else: logging.critical("Running ModelInfo without SEIR") @@ -208,7 +208,7 @@ def __init__( elif self.outcome_modifiers_scenario is not None: if config["outcome_modifiers"].exists(): raise ValueError( - "An outcome modifiers scenario was provided to `ModelInfo` but there is no `outcome_modifiers` section in the config." + "A `outcome_modifiers_scenario` argument was provided to `ModelInfo` but there is no `outcome_modifiers` section in the config." ) else: self.outcome_modifiers_scenario = None @@ -218,7 +218,7 @@ def __init__( ) elif self.outcome_modifiers_scenario is not None: raise ValueError( - "An outcome modifiers scenario was provided to `ModelInfo` but there is no `outcome_modifiers` section in the config." + "A `outcome_modifiers_scenario` argument was provided to `ModelInfo` but there is no `outcomes` section in the config." ) else: logging.info("Running `ModelInfo` without outcomes.") diff --git a/flepimop/gempyor_pkg/src/gempyor/seeding.py b/flepimop/gempyor_pkg/src/gempyor/seeding.py index c341ed93c..a2ae8bb88 100644 --- a/flepimop/gempyor_pkg/src/gempyor/seeding.py +++ b/flepimop/gempyor_pkg/src/gempyor/seeding.py @@ -158,8 +158,6 @@ def get_from_config(self, sim_id: int, modinf) -> nb.typed.Dict: ) elif method == "FolderDraw" or method == "FromFile": amounts = seeding["amount"] - else: - raise ValueError(f"Unknown seeding method given, '{method}'.") return _DataFrame2NumbaDict(df=seeding, amounts=amounts, modinf=modinf) diff --git a/flepimop/gempyor_pkg/src/gempyor/statistics.py b/flepimop/gempyor_pkg/src/gempyor/statistics.py index b6ced5e6d..180dbe80e 100644 --- a/flepimop/gempyor_pkg/src/gempyor/statistics.py +++ b/flepimop/gempyor_pkg/src/gempyor/statistics.py @@ -257,8 +257,8 @@ def llik(self, model_data: xr.DataArray, gt_data: xr.DataArray) -> xr.DataArray: } if self.dist not in dist_map: raise ValueError( - f"Invalid distribution specified [received: '{self.dist}']. " - f"Valid distributions: '{dist_map}'." + f"Invalid distribution specified: '{self.dist}'. " + f"Valid distributions: '{dist_map.keys()}'." ) if self.dist in ["pois", "nbinom"]: model_data = model_data.astype(int) From d5fe360a5f0854a3006a2967e6958b562a46323d Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Fri, 22 Nov 2024 16:06:52 -0500 Subject: [PATCH 29/56] Regex update in `test_model_info.py` --- flepimop/gempyor_pkg/tests/seir/test_model_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/seir/test_model_info.py b/flepimop/gempyor_pkg/tests/seir/test_model_info.py index baad036b4..7cfc78d4e 100644 --- a/flepimop/gempyor_pkg/tests/seir/test_model_info.py +++ b/flepimop/gempyor_pkg/tests/seir/test_model_info.py @@ -46,7 +46,7 @@ def test_ModelInfo_init_tf_is_ahead_of_ti_fail(self): config["start_date"] = "2022-01-02" with pytest.raises( ValueError, - match=r"Time to finish.*is less than or equal to time to start.*", + match=r"Final time.*is less than or equal to initial time.*", ): s = ModelInfo( config=config, From 9c6e1f1f102b11382c50a0b1e738a2ceda72e6bf Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Tue, 26 Nov 2024 17:13:57 -0500 Subject: [PATCH 30/56] Regex update in `test_model_info.py` --- flepimop/gempyor_pkg/tests/seir/test_model_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/seir/test_model_info.py b/flepimop/gempyor_pkg/tests/seir/test_model_info.py index 7cfc78d4e..25c3c00c8 100644 --- a/flepimop/gempyor_pkg/tests/seir/test_model_info.py +++ b/flepimop/gempyor_pkg/tests/seir/test_model_info.py @@ -46,7 +46,7 @@ def test_ModelInfo_init_tf_is_ahead_of_ti_fail(self): config["start_date"] = "2022-01-02" with pytest.raises( ValueError, - match=r"Final time.*is less than or equal to initial time.*", + match=rf"Final time ('{config["end_date"]}') is less than or equal to initial time ('{config["start_date"]}').", ): s = ModelInfo( config=config, From f7c1ad08f832a42d7e5b007aea3473ecc11b87ae Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Tue, 26 Nov 2024 17:17:26 -0500 Subject: [PATCH 31/56] Regex update in `test_model_info.py` --- flepimop/gempyor_pkg/tests/seir/test_model_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/seir/test_model_info.py b/flepimop/gempyor_pkg/tests/seir/test_model_info.py index 25c3c00c8..714763204 100644 --- a/flepimop/gempyor_pkg/tests/seir/test_model_info.py +++ b/flepimop/gempyor_pkg/tests/seir/test_model_info.py @@ -46,7 +46,7 @@ def test_ModelInfo_init_tf_is_ahead_of_ti_fail(self): config["start_date"] = "2022-01-02" with pytest.raises( ValueError, - match=rf"Final time ('{config["end_date"]}') is less than or equal to initial time ('{config["start_date"]}').", + match=rf"Final time ('{config['end_date']}') is less than or equal to initial time ('{config['start_date']}').", ): s = ModelInfo( config=config, From ebe2ebcfb36a546cd9d86d5c0a5404e3742923f7 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Wed, 27 Nov 2024 08:11:42 -0500 Subject: [PATCH 32/56] Typo in `model_info.py` --- flepimop/gempyor_pkg/src/gempyor/model_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/src/gempyor/model_info.py b/flepimop/gempyor_pkg/src/gempyor/model_info.py index 3ba989cf3..3b6cf5afc 100644 --- a/flepimop/gempyor_pkg/src/gempyor/model_info.py +++ b/flepimop/gempyor_pkg/src/gempyor/model_info.py @@ -19,7 +19,7 @@ def __init__(self, config: confuse.ConfigView): self.tf = config["end_date"].as_date() if self.tf <= self.ti: raise ValueError( - f"Final time ('{self.tf}') is less than or equal to initial time('{self.ti}')." + f"Final time ('{self.tf}') is less than or equal to initial time ('{self.ti}')." ) self.n_days = (self.tf - self.ti).days + 1 self.dates = pd.date_range(start=self.ti, end=self.tf, freq="D") From 57240be501036c8ce13f74066f50310348429e34 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Wed, 27 Nov 2024 08:19:15 -0500 Subject: [PATCH 33/56] Using `re.escape()` to escape non-alphanumeric characters in the regex --- flepimop/gempyor_pkg/tests/seir/test_model_info.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/seir/test_model_info.py b/flepimop/gempyor_pkg/tests/seir/test_model_info.py index 714763204..b241ba263 100644 --- a/flepimop/gempyor_pkg/tests/seir/test_model_info.py +++ b/flepimop/gempyor_pkg/tests/seir/test_model_info.py @@ -4,6 +4,7 @@ import pandas as pd import pytest import confuse +import re from gempyor.model_info import ModelInfo, subpopulation_structure @@ -46,7 +47,7 @@ def test_ModelInfo_init_tf_is_ahead_of_ti_fail(self): config["start_date"] = "2022-01-02" with pytest.raises( ValueError, - match=rf"Final time ('{config['end_date']}') is less than or equal to initial time ('{config['start_date']}').", + match=re.escape(rf"Final time ('{config['end_date']}') is less than or equal to initial time ('{config['start_date']}')."), ): s = ModelInfo( config=config, From cc52fb7ad803a938fcd2160c4c15f1f9d3fda7fc Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Mon, 2 Dec 2024 08:41:39 -0500 Subject: [PATCH 34/56] Regex update in `test_seir.py` Updating a regex to match on a specific value rather than arbitrary wording of error message. --- flepimop/gempyor_pkg/tests/seir/test_seir.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/seir/test_seir.py b/flepimop/gempyor_pkg/tests/seir/test_seir.py index 9cf89032e..c81dea883 100644 --- a/flepimop/gempyor_pkg/tests/seir/test_seir.py +++ b/flepimop/gempyor_pkg/tests/seir/test_seir.py @@ -129,7 +129,7 @@ def test_constant_population_legacy_integration(): def test_constant_population_rk4jit_integration_fail(): with pytest.raises( - ValueError, match=r".*integration method only supports deterministic integration.*" + ValueError, match=rf"'{modinf.seir_config["integration"]["method"].get()}' integration method only supports deterministic integration.*" ): config.set_file(f"{DATA_DIR}/config.yml") From 328dacfd0de8ac7079bc93e500e5a464b85d85f2 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Mon, 2 Dec 2024 09:09:02 -0500 Subject: [PATCH 35/56] Syntax update in `test_seir.py` --- flepimop/gempyor_pkg/tests/seir/test_seir.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/seir/test_seir.py b/flepimop/gempyor_pkg/tests/seir/test_seir.py index c81dea883..a9e3db633 100644 --- a/flepimop/gempyor_pkg/tests/seir/test_seir.py +++ b/flepimop/gempyor_pkg/tests/seir/test_seir.py @@ -129,7 +129,7 @@ def test_constant_population_legacy_integration(): def test_constant_population_rk4jit_integration_fail(): with pytest.raises( - ValueError, match=rf"'{modinf.seir_config["integration"]["method"].get()}' integration method only supports deterministic integration.*" + ValueError, match=rf"'{modinf.seir_config['integration']['method'].get()}' integration method only supports deterministic integration.*" ): config.set_file(f"{DATA_DIR}/config.yml") From e7621d93fe65ef7f3ba1c70e449a3a8166451b55 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Mon, 2 Dec 2024 09:32:01 -0500 Subject: [PATCH 36/56] Update test_seir.py --- flepimop/gempyor_pkg/tests/seir/test_seir.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/seir/test_seir.py b/flepimop/gempyor_pkg/tests/seir/test_seir.py index a9e3db633..eeb04fff8 100644 --- a/flepimop/gempyor_pkg/tests/seir/test_seir.py +++ b/flepimop/gempyor_pkg/tests/seir/test_seir.py @@ -129,7 +129,7 @@ def test_constant_population_legacy_integration(): def test_constant_population_rk4jit_integration_fail(): with pytest.raises( - ValueError, match=rf"'{modinf.seir_config['integration']['method'].get()}' integration method only supports deterministic integration.*" + ValueError, match=r"'rk4.jit' integration method only supports deterministic integration.*" ): config.set_file(f"{DATA_DIR}/config.yml") From d74a214b6ef93aa0d72a7d6be7e5d679fb13e13a Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Mon, 2 Dec 2024 11:19:05 -0500 Subject: [PATCH 37/56] Regex update in `test_statistic_class.py` --- flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py b/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py index 5ec48ba76..31b752ded 100644 --- a/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py +++ b/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py @@ -248,7 +248,7 @@ def test_unsupported_regularizations_value_error( ] if reg_name not in ["forecast", "allsubpop"] ) - with pytest.raises(ValueError, match=r"^Unsupported regularization \[received:.*$"): + with pytest.raises(ValueError, match=rf"^Unsupported regularization \[received: '{mock_inputs.config.get('regularize', [])}'\]"): mock_inputs.create_statistic_instance() @pytest.mark.parametrize("factory", all_valid_factories) From d5087931e56d17a4e977e59fbb6d186593522c6d Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Mon, 2 Dec 2024 11:26:22 -0500 Subject: [PATCH 38/56] Regex update in `test_statistic_class.py` --- flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py b/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py index 31b752ded..fa6964a7f 100644 --- a/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py +++ b/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py @@ -248,7 +248,7 @@ def test_unsupported_regularizations_value_error( ] if reg_name not in ["forecast", "allsubpop"] ) - with pytest.raises(ValueError, match=rf"^Unsupported regularization \[received: '{mock_inputs.config.get('regularize', [])}'\]"): + with pytest.raises(ValueError, match=rf"^Unsupported regularization \[received: 'invalid'\]"): mock_inputs.create_statistic_instance() @pytest.mark.parametrize("factory", all_valid_factories) From 6fc2a5a6b2a41c9a6499148631cf88be518022d6 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Mon, 2 Dec 2024 13:51:03 -0500 Subject: [PATCH 39/56] Regex update in `test_statistic_class.py` --- flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py b/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py index fa6964a7f..268b9ce21 100644 --- a/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py +++ b/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py @@ -520,7 +520,7 @@ def test_compute_logloss_data_misshape_value_error( model_rows, model_cols = mock_inputs.model_data[mock_inputs.config["sim_var"]].shape gt_rows, gt_cols = mock_inputs.gt_data[mock_inputs.config["data_var"]].shape - expected_match = rf".*do not have the same shape:.*" + expected_match = rf".*'{mock_inputs.model_data[mock_inputs.config["sim_var"]].shape}' !=.*'{mock_inputs.gt_data[mock_inputs.config["data_var"]].shape}'" with pytest.raises(ValueError, match=expected_match): statistic.compute_logloss(mock_inputs.model_data, mock_inputs.gt_data) From f8b9dc31cf05e7517b99604b121905e8de1c0686 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Mon, 2 Dec 2024 13:56:06 -0500 Subject: [PATCH 40/56] Syntax change in `test_statistic_class.py` --- flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py b/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py index 268b9ce21..4531d5490 100644 --- a/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py +++ b/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py @@ -520,7 +520,7 @@ def test_compute_logloss_data_misshape_value_error( model_rows, model_cols = mock_inputs.model_data[mock_inputs.config["sim_var"]].shape gt_rows, gt_cols = mock_inputs.gt_data[mock_inputs.config["data_var"]].shape - expected_match = rf".*'{mock_inputs.model_data[mock_inputs.config["sim_var"]].shape}' !=.*'{mock_inputs.gt_data[mock_inputs.config["data_var"]].shape}'" + expected_match = rf".*'{mock_inputs.model_data[mock_inputs.config['sim_var']].shape}' !=.*'{mock_inputs.gt_data[mock_inputs.config['data_var']].shape}'" with pytest.raises(ValueError, match=expected_match): statistic.compute_logloss(mock_inputs.model_data, mock_inputs.gt_data) From ad623ab86386f2ae573993e919c289051aaa087c Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Mon, 2 Dec 2024 14:12:25 -0500 Subject: [PATCH 41/56] Regex update in `test_statistic_class.py` --- flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py b/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py index 4531d5490..18a5e94b0 100644 --- a/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py +++ b/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py @@ -520,7 +520,7 @@ def test_compute_logloss_data_misshape_value_error( model_rows, model_cols = mock_inputs.model_data[mock_inputs.config["sim_var"]].shape gt_rows, gt_cols = mock_inputs.gt_data[mock_inputs.config["data_var"]].shape - expected_match = rf".*'{mock_inputs.model_data[mock_inputs.config['sim_var']].shape}' !=.*'{mock_inputs.gt_data[mock_inputs.config['data_var']].shape}'" + expected_match = rf".*'{mock_inputs.model_data[mock_inputs.config['sim_var']].shape}'.*'{mock_inputs.gt_data[mock_inputs.config['data_var']].shape}'" with pytest.raises(ValueError, match=expected_match): statistic.compute_logloss(mock_inputs.model_data, mock_inputs.gt_data) From a3b5f621d6d0400cf8594574ede4e7a837c98fac Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Mon, 2 Dec 2024 14:26:29 -0500 Subject: [PATCH 42/56] Testing a regex in `test_statistic_class.py` --- .../gempyor_pkg/tests/statistics/test_statistic_class.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py b/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py index 18a5e94b0..274a344bf 100644 --- a/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py +++ b/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py @@ -520,7 +520,11 @@ def test_compute_logloss_data_misshape_value_error( model_rows, model_cols = mock_inputs.model_data[mock_inputs.config["sim_var"]].shape gt_rows, gt_cols = mock_inputs.gt_data[mock_inputs.config["data_var"]].shape - expected_match = rf".*'{mock_inputs.model_data[mock_inputs.config['sim_var']].shape}'.*'{mock_inputs.gt_data[mock_inputs.config['data_var']].shape}'" + expected_match = ( + rf"`model_data` and `gt_data` do not have the same shape: " + rf"`model_data.shape` = '{mock_inputs.model_data[mock_inputs.config['sim_var']].shape}' " + rf"!= `gt_data.shape` = '{mock_inputs.gt_data[mock_inputs.config['data_var']].shape}'." + ) with pytest.raises(ValueError, match=expected_match): statistic.compute_logloss(mock_inputs.model_data, mock_inputs.gt_data) From 1daed72da55c2a9f09880bb75064221e3503a0f3 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Mon, 2 Dec 2024 14:41:03 -0500 Subject: [PATCH 43/56] Using re.escape() to escape non-alphanumeric characters in the regex --- flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py b/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py index 274a344bf..bc2007270 100644 --- a/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py +++ b/flepimop/gempyor_pkg/tests/statistics/test_statistic_class.py @@ -8,6 +8,7 @@ import pytest import scipy import xarray as xr +import re from gempyor.statistics import Statistic from gempyor.testing import create_confuse_configview_from_dict @@ -520,7 +521,7 @@ def test_compute_logloss_data_misshape_value_error( model_rows, model_cols = mock_inputs.model_data[mock_inputs.config["sim_var"]].shape gt_rows, gt_cols = mock_inputs.gt_data[mock_inputs.config["data_var"]].shape - expected_match = ( + expected_match = re.escape( rf"`model_data` and `gt_data` do not have the same shape: " rf"`model_data.shape` = '{mock_inputs.model_data[mock_inputs.config['sim_var']].shape}' " rf"!= `gt_data.shape` = '{mock_inputs.gt_data[mock_inputs.config['data_var']].shape}'." From 239f5a0bc63988204c3d57d4a502b4b3a68acf7a Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Mon, 2 Dec 2024 14:50:16 -0500 Subject: [PATCH 44/56] Regex update in `test_random_distribution_sampler.py` --- .../gempyor_pkg/tests/utils/test_random_distribution_sampler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py b/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py index 596d296c1..f4e26115d 100644 --- a/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py +++ b/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py @@ -14,7 +14,7 @@ class TestRandomDistributionSampler: def test_not_implemented_error_exception(self, distribution: str) -> None: with pytest.raises( NotImplementedError, - match=rf"^Unknown distribution \[received.*", + match=rf"^Unknown distribution \[received '{distribution}'\]", ): random_distribution_sampler(distribution) From 50b91ce36c10dc4b1adcb10183a7d0738046996e Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Mon, 2 Dec 2024 15:04:16 -0500 Subject: [PATCH 45/56] Regex update in `test_random_distribution_sampler.py` --- .../tests/utils/test_random_distribution_sampler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py b/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py index f4e26115d..f3fe2c899 100644 --- a/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py +++ b/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py @@ -14,7 +14,7 @@ class TestRandomDistributionSampler: def test_not_implemented_error_exception(self, distribution: str) -> None: with pytest.raises( NotImplementedError, - match=rf"^Unknown distribution \[received '{distribution}'\]", + match=rf"Unknown distribution [received '{distribution}']", ): random_distribution_sampler(distribution) @@ -22,7 +22,7 @@ def test_not_implemented_error_exception(self, distribution: str) -> None: def test_binomial_p_value_error(self, p: float) -> None: with pytest.raises( ValueError, - match=r"^Invalid\s`p-value`.*\sis\sout\sof\srange.*$", + match=rf"Invalid `p-value`: '{p}' is out of range [0,1].", ): random_distribution_sampler("binomial", n=100, p=p) From 84fb06796feed2137af1b66a82fca33f82b1cc5d Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Mon, 2 Dec 2024 15:13:41 -0500 Subject: [PATCH 46/56] Update test_random_distribution_sampler.py --- .../gempyor_pkg/tests/utils/test_random_distribution_sampler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py b/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py index f3fe2c899..148686996 100644 --- a/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py +++ b/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py @@ -14,7 +14,7 @@ class TestRandomDistributionSampler: def test_not_implemented_error_exception(self, distribution: str) -> None: with pytest.raises( NotImplementedError, - match=rf"Unknown distribution [received '{distribution}']", + match=rf"Unknown distribution [received: '{distribution}']", ): random_distribution_sampler(distribution) From 4bf61fb4dad446a63fa85d8011f9db29c4bd1bb2 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Mon, 2 Dec 2024 15:23:13 -0500 Subject: [PATCH 47/56] Update test_random_distribution_sampler.py --- .../gempyor_pkg/tests/utils/test_random_distribution_sampler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py b/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py index 148686996..0d94c0456 100644 --- a/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py +++ b/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py @@ -14,7 +14,7 @@ class TestRandomDistributionSampler: def test_not_implemented_error_exception(self, distribution: str) -> None: with pytest.raises( NotImplementedError, - match=rf"Unknown distribution [received: '{distribution}']", + match=rf"Unknown distribution [received: '{distribution}'].", ): random_distribution_sampler(distribution) From 660795fbbd280533d5772ae058ba2df2cb8501fd Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Mon, 2 Dec 2024 15:29:30 -0500 Subject: [PATCH 48/56] Using `re.escape()` in regexs --- .../tests/utils/test_random_distribution_sampler.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py b/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py index 0d94c0456..0dcd110fb 100644 --- a/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py +++ b/flepimop/gempyor_pkg/tests/utils/test_random_distribution_sampler.py @@ -4,6 +4,7 @@ import numpy as np import pytest +import re from gempyor.testing import partials_are_similar from gempyor.utils import random_distribution_sampler @@ -14,7 +15,7 @@ class TestRandomDistributionSampler: def test_not_implemented_error_exception(self, distribution: str) -> None: with pytest.raises( NotImplementedError, - match=rf"Unknown distribution [received: '{distribution}'].", + match=re.escape(rf"Unknown distribution [received: '{distribution}']."), ): random_distribution_sampler(distribution) @@ -22,7 +23,7 @@ def test_not_implemented_error_exception(self, distribution: str) -> None: def test_binomial_p_value_error(self, p: float) -> None: with pytest.raises( ValueError, - match=rf"Invalid `p-value`: '{p}' is out of range [0,1].", + match=re.escape(rf"Invalid `p-value`: '{p}' is out of range [0,1]."), ): random_distribution_sampler("binomial", n=100, p=p) From 00120cf2019efd0d273865ef16acf5fa1c91dfa0 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Mon, 2 Dec 2024 15:40:12 -0500 Subject: [PATCH 49/56] Regex update in `test_read_df.py` --- flepimop/gempyor_pkg/tests/utils/test_read_df.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flepimop/gempyor_pkg/tests/utils/test_read_df.py b/flepimop/gempyor_pkg/tests/utils/test_read_df.py index 676f5d699..0ed485852 100644 --- a/flepimop/gempyor_pkg/tests/utils/test_read_df.py +++ b/flepimop/gempyor_pkg/tests/utils/test_read_df.py @@ -38,13 +38,13 @@ def test_raises_not_implemented_error(self) -> None: """ with pytest.raises( expected_exception=NotImplementedError, - match=r".*Supported extensions are `.csv` or `.parquet`.", + match=rf"Invalid extension provided: '.txt'. Supported extensions are `.csv` or `.parquet`.", ) as _: with NamedTemporaryFile(suffix=".txt") as temp_file: read_df(fname=temp_file.name) with pytest.raises( expected_exception=NotImplementedError, - match=r".*Supported extensions are `.csv` or `.parquet`.", + match=rf"Invalid extension provided: '.txt'. Supported extensions are `.csv` or `.parquet`.", ) as _: with NamedTemporaryFile(suffix=".txt") as temp_file: fname = temp_file.name[:-4] From 0a05cb546e3bb29c11cd934060d56235d4875700 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Mon, 2 Dec 2024 15:46:49 -0500 Subject: [PATCH 50/56] Update utils.py --- flepimop/gempyor_pkg/src/gempyor/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/src/gempyor/utils.py b/flepimop/gempyor_pkg/src/gempyor/utils.py index a937b53b4..f8852e17a 100644 --- a/flepimop/gempyor_pkg/src/gempyor/utils.py +++ b/flepimop/gempyor_pkg/src/gempyor/utils.py @@ -95,7 +95,7 @@ def read_df( elif path.suffix == ".parquet": return pd.read_parquet(path, engine="pyarrow") raise NotImplementedError( - f"Invalid extension provided: '{path.suffix[1:]}'. Supported extensions are `.csv` or `.parquet`." + f"Invalid extension provided: '.{path.suffix[1:]}'. Supported extensions are `.csv` or `.parquet`." ) From 190c4839b8efd21959ff6d9fd30168fb46e6eb18 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Tue, 3 Dec 2024 15:11:23 -0500 Subject: [PATCH 51/56] Regex update in `test_utils.py` --- flepimop/gempyor_pkg/tests/utils/test_read_df.py | 4 ++-- flepimop/gempyor_pkg/tests/utils/test_utils.py | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/flepimop/gempyor_pkg/tests/utils/test_read_df.py b/flepimop/gempyor_pkg/tests/utils/test_read_df.py index 0ed485852..b591aecd9 100644 --- a/flepimop/gempyor_pkg/tests/utils/test_read_df.py +++ b/flepimop/gempyor_pkg/tests/utils/test_read_df.py @@ -38,13 +38,13 @@ def test_raises_not_implemented_error(self) -> None: """ with pytest.raises( expected_exception=NotImplementedError, - match=rf"Invalid extension provided: '.txt'. Supported extensions are `.csv` or `.parquet`.", + match=r"Invalid extension provided: '.txt'. Supported extensions are `.csv` or `.parquet`.", ) as _: with NamedTemporaryFile(suffix=".txt") as temp_file: read_df(fname=temp_file.name) with pytest.raises( expected_exception=NotImplementedError, - match=rf"Invalid extension provided: '.txt'. Supported extensions are `.csv` or `.parquet`.", + match=r"Invalid extension provided: '.txt'. Supported extensions are `.csv` or `.parquet`.", ) as _: with NamedTemporaryFile(suffix=".txt") as temp_file: fname = temp_file.name[:-4] diff --git a/flepimop/gempyor_pkg/tests/utils/test_utils.py b/flepimop/gempyor_pkg/tests/utils/test_utils.py index c57ac900e..384cae617 100644 --- a/flepimop/gempyor_pkg/tests/utils/test_utils.py +++ b/flepimop/gempyor_pkg/tests/utils/test_utils.py @@ -38,8 +38,7 @@ def test_read_df_and_write_success(fname, extension): ) def test_read_df_and_write_fail(fname, extension): with pytest.raises( - NotImplementedError, match=r".*Supported extensions are `.csv` or `.parquet`." - ): + NotImplementedError, match=rf"Invalid extension provided: '{extension}'. Supported extensions are `.csv` or `.parquet`."): os.chdir(tmp_path) os.makedirs("data", exist_ok=True) os.chdir("data") @@ -58,7 +57,7 @@ def test_read_df_and_write_fail(fname, extension): @pytest.mark.parametrize(("fname", "extension"), [("mobility", "")]) def test_read_df_fail(fname, extension): - with pytest.raises(NotImplementedError, match=r".*Invalid.*extension.*"): + with pytest.raises(NotImplementedError, match=rf"Invalid extension provided: '{extension}'. Supported extensions are `.csv` or `.parquet`."): os.chdir(tmp_path) utils.read_df(fname=f"{DATA_DIR}/" + fname, extension=extension) From fb6c9ed967bd63c6afbc40c29475be2d11f2adeb Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Tue, 3 Dec 2024 15:33:48 -0500 Subject: [PATCH 52/56] Regex update in `test_utils.py` --- flepimop/gempyor_pkg/tests/utils/test_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flepimop/gempyor_pkg/tests/utils/test_utils.py b/flepimop/gempyor_pkg/tests/utils/test_utils.py index 384cae617..817b8db55 100644 --- a/flepimop/gempyor_pkg/tests/utils/test_utils.py +++ b/flepimop/gempyor_pkg/tests/utils/test_utils.py @@ -38,7 +38,7 @@ def test_read_df_and_write_success(fname, extension): ) def test_read_df_and_write_fail(fname, extension): with pytest.raises( - NotImplementedError, match=rf"Invalid extension provided: '{extension}'. Supported extensions are `.csv` or `.parquet`."): + NotImplementedError, match=r"Invalid extension provided: ''. Supported extensions are `.csv` or `.parquet`."): os.chdir(tmp_path) os.makedirs("data", exist_ok=True) os.chdir("data") @@ -57,7 +57,7 @@ def test_read_df_and_write_fail(fname, extension): @pytest.mark.parametrize(("fname", "extension"), [("mobility", "")]) def test_read_df_fail(fname, extension): - with pytest.raises(NotImplementedError, match=rf"Invalid extension provided: '{extension}'. Supported extensions are `.csv` or `.parquet`."): + with pytest.raises(NotImplementedError, match=r"Invalid extension provided: ''. Supported extensions are `.csv` or `.parquet`."): os.chdir(tmp_path) utils.read_df(fname=f"{DATA_DIR}/" + fname, extension=extension) From 8255da25ae91c077d233b6ca9b5347d2c4518aed Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Tue, 3 Dec 2024 16:00:52 -0500 Subject: [PATCH 53/56] Update test_utils.py --- flepimop/gempyor_pkg/tests/utils/test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/utils/test_utils.py b/flepimop/gempyor_pkg/tests/utils/test_utils.py index 817b8db55..d83bc04e8 100644 --- a/flepimop/gempyor_pkg/tests/utils/test_utils.py +++ b/flepimop/gempyor_pkg/tests/utils/test_utils.py @@ -57,7 +57,7 @@ def test_read_df_and_write_fail(fname, extension): @pytest.mark.parametrize(("fname", "extension"), [("mobility", "")]) def test_read_df_fail(fname, extension): - with pytest.raises(NotImplementedError, match=r"Invalid extension provided: ''. Supported extensions are `.csv` or `.parquet`."): + with pytest.raises(NotImplementedError, match=r"Invalid extension provided: '.'. Supported extensions are `.csv` or `.parquet`."): os.chdir(tmp_path) utils.read_df(fname=f"{DATA_DIR}/" + fname, extension=extension) From 8a5e772939d5e1d7261480252ab88e3cd9bc6455 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Tue, 3 Dec 2024 16:17:48 -0500 Subject: [PATCH 54/56] Regex update in `test_write_df.py` --- flepimop/gempyor_pkg/tests/utils/test_write_df.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flepimop/gempyor_pkg/tests/utils/test_write_df.py b/flepimop/gempyor_pkg/tests/utils/test_write_df.py index 8f4e18baf..e63afa2e5 100644 --- a/flepimop/gempyor_pkg/tests/utils/test_write_df.py +++ b/flepimop/gempyor_pkg/tests/utils/test_write_df.py @@ -30,13 +30,13 @@ def test_raises_not_implemented_error(self) -> None: """ with pytest.raises( expected_exception=NotImplementedError, - match=r".*Supported extensions are `.csv` or `.parquet`.", + match=r"Invalid extension provided: '.txt'. Supported extensions are `.csv` or `.parquet`.", ) as _: with NamedTemporaryFile(suffix=".txt") as temp_file: write_df(fname=temp_file.name, df=self.sample_df) with pytest.raises( expected_exception=NotImplementedError, - match=r".*Supported extensions are `.csv` or `.parquet`.", + match=r"Invalid extension provided: '.txt'. Supported extensions are `.csv` or `.parquet`.", ) as _: with NamedTemporaryFile(suffix=".txt") as temp_file: fname = temp_file.name[:-4] From 6ce17606aa0644fa8dcb54b36ccf13b5e5ca9023 Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Tue, 3 Dec 2024 16:25:40 -0500 Subject: [PATCH 55/56] Update utils.py --- flepimop/gempyor_pkg/src/gempyor/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/src/gempyor/utils.py b/flepimop/gempyor_pkg/src/gempyor/utils.py index f8852e17a..9732d70c2 100644 --- a/flepimop/gempyor_pkg/src/gempyor/utils.py +++ b/flepimop/gempyor_pkg/src/gempyor/utils.py @@ -58,7 +58,7 @@ def write_df( elif path.suffix == ".parquet": return df.to_parquet(path, index=False, engine="pyarrow") raise NotImplementedError( - f"Invalid extension provided: '{path.suffix[1:]}'. Supported extensions are `.csv` or `.parquet`." + f"Invalid extension provided: '.{path.suffix[1:]}'. Supported extensions are `.csv` or `.parquet`." ) From 178861a38184c248ee9e7651fc86a25065e4775d Mon Sep 17 00:00:00 2001 From: Emily Przykucki Date: Tue, 3 Dec 2024 16:38:41 -0500 Subject: [PATCH 56/56] Update test_utils.py --- flepimop/gempyor_pkg/tests/utils/test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flepimop/gempyor_pkg/tests/utils/test_utils.py b/flepimop/gempyor_pkg/tests/utils/test_utils.py index d83bc04e8..7b6606166 100644 --- a/flepimop/gempyor_pkg/tests/utils/test_utils.py +++ b/flepimop/gempyor_pkg/tests/utils/test_utils.py @@ -38,7 +38,7 @@ def test_read_df_and_write_success(fname, extension): ) def test_read_df_and_write_fail(fname, extension): with pytest.raises( - NotImplementedError, match=r"Invalid extension provided: ''. Supported extensions are `.csv` or `.parquet`."): + NotImplementedError, match=r"Invalid extension provided: '.'. Supported extensions are `.csv` or `.parquet`."): os.chdir(tmp_path) os.makedirs("data", exist_ok=True) os.chdir("data")