Skip to content
Open
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
5 changes: 2 additions & 3 deletions dowhy/causal_refuters/dummy_outcome_refuter.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,14 +757,13 @@ def preprocess_data_by_treatment(
std_dev = data[treatment_variable_name].std()
num_bins = (data.max() - data.min()) / (bucket_size_scale_factor * std_dev)
data["bins"] = pd.cut(data[treatment_variable_name], num_bins)
groups = data.groupby("bins")
groups = data.groupby("bins", observed=False)
data.drop("bins", axis=1, inplace=True)
return groups

elif "categorical" in variable_type.name:
# Action for categorical variables
groups = data.groupby(treatment_variable_name)
groups = data.groupby("bins")
groups = data.groupby(treatment_variable_name, observed=False)
return groups
else:
raise ValueError("Passed {}. Expected bool, float, int or categorical.".format(variable_type.name))
Expand Down
12 changes: 12 additions & 0 deletions tests/causal_refuters/test_dummy_outcome_refuter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ def test_refutation_dummy_outcome_refuter_default_binary_treatment(
refuter_tester = SimpleRefuter(error_tolerence, estimator_method, "dummy_outcome_refuter")
refuter_tester.binary_treatment_testsuite(tests_to_run="atleast-one-common-cause", num_samples=num_samples)

@mark.parametrize(
["error_tolerance", "estimator_method", "num_samples"],
[(0.1, "backdoor.propensity_score_matching", 1000)],
)
def test_refutation_dummy_outcome_refuter_default_categorical_treatment(
self, error_tolerance, estimator_method, num_samples
):
# Regression test for #1316: the categorical branch had a copy-paste error that tried to
# groupby("bins") which doesn't exist for categorical treatments, raising KeyError.
refuter_tester = SimpleRefuter(error_tolerance, estimator_method, "dummy_outcome_refuter")
refuter_tester.categorical_treatment_testsuite(tests_to_run="atleast-one-common-cause", num_samples=num_samples)
Comment thread
emrekiciman marked this conversation as resolved.

@mark.parametrize(
["error_tolerence", "estimator_method", "transformations"],
[(0.05, "iv.instrumental_variable", [("zero", ""), ("noise", {"std_dev": 1})])],
Expand Down