Skip to content

Avoid returning defaultdict directly #709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions econml/_shap.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ def cmd_func(X):
data=shap_out.data, main_effects=shap_out.main_effects,
feature_names=shap_out.feature_names)
shap_outs[output_names[i]][treatment_names[0]] = shap_out_new
return shap_outs
# return plain dictionary so that erroneous accesses don't half work (see #708)
return dict(shap_outs)


def _shap_explain_model_cate(cme_model, models, X, d_t, d_y, featurizer=None, feature_names=None,
Expand Down Expand Up @@ -176,7 +177,8 @@ def _shap_explain_model_cate(cme_model, models, X, d_t, d_y, featurizer=None, fe
else:
shap_outs[output_names[0]][treatment_names[i]] = shap_out

return shap_outs
# return plain dictionary so that erroneous accesses don't half work (see #708)
return dict(shap_outs)


def _shap_explain_joint_linear_model_cate(model_final, X, d_t, d_y, fit_cate_intercept,
Expand Down Expand Up @@ -258,7 +260,8 @@ def _shap_explain_joint_linear_model_cate(model_final, X, d_t, d_y, fit_cate_int
feature_names=shap_out.feature_names)
shap_outs[output_names[0]][treatment_names[i]] = shap_out_new

return shap_outs
# return plain dictionary so that erroneous accesses don't half work (see #708)
return dict(shap_outs)


def _shap_explain_multitask_model_cate(cme_model, multitask_model_cate, X, d_t, d_y, featurizer=None,
Expand Down Expand Up @@ -352,7 +355,8 @@ def _shap_explain_multitask_model_cate(cme_model, multitask_model_cate, X, d_t,
shap_outs[output_names[j]][treatment_names[i]] = shap_out_new
else:
shap_outs[output_names[j]][treatment_names[0]] = shap_out
return shap_outs
# return plain dictionary so that erroneous accesses don't half work (see #708)
return dict(shap_outs)


def _define_names(d_t, d_y, treatment_names, output_names, feature_names, input_names, featurizer):
Expand Down
4 changes: 3 additions & 1 deletion econml/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,9 @@ def transpose_dictionary(d):
for key1, value in d.items():
for key2, val in value.items():
output[key2][key1] = val
return output

# return plain dictionary so that erroneous accesses don't half work (see e.g. #708)
return dict(output)


def reshape_arrays_2dim(length, *args):
Expand Down