OpenSourceEconomics/respy

Raise a more informative error message.

mo2561057 opened this issue · 1 comments

respy/respy/solve.py

Lines 74 to 88 in fd580c3

for i, choice in enumerate(optim_paras["choices"]):
if f"wage_{choice}" in optim_paras:
wage_columns = optim_paras[f"wage_{choice}"].index
log_wage = np.dot(
states[wage_columns].to_numpy(dtype=COVARIATES_DOT_PRODUCT_DTYPE),
optim_paras[f"wage_{choice}"].to_numpy(),
)
wages[:, i] = np.exp(log_wage)
if f"nonpec_{choice}" in optim_paras:
nonpec_columns = optim_paras[f"nonpec_{choice}"].index
nonpecs[:, i] = np.dot(
states[nonpec_columns].to_numpy(dtype=COVARIATES_DOT_PRODUCT_DTYPE),
optim_paras[f"nonpec_{choice}"].to_numpy(),
)

This is a part of the code that will frequently throw errors due when dealing with large models.
If there is a small spelling mistake or a corrupted row in the params file there will be a key error here.
I think we could provide the user with a more informative message indicating that this is probably due to a variable that is misspelled or not in the covariates.

Very good idea!