Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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=True)
Comment thread
emrekiciman marked this conversation as resolved.
Outdated
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=True)
Comment thread
emrekiciman marked this conversation as resolved.
Outdated
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_tolerence", "estimator_method", "num_samples"],
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter name error_tolerence is misspelled (tolerence vs tolerance). Since this is newly added test code, consider renaming the local test parameter to error_tolerance for readability (keeping the passed value the same).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

[(0.1, "backdoor.propensity_score_matching", 1000)],
)
def test_refutation_dummy_outcome_refuter_default_categorical_treatment(
self, error_tolerence, estimator_method, num_samples
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter name error_tolerence is misspelled (tolerence vs tolerance). Since this is newly added test code, consider renaming the local test parameter to error_tolerance for readability (keeping the passed value the same).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

):
# 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_tolerence, estimator_method, "dummy_outcome_refuter")
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter name error_tolerence is misspelled (tolerence vs tolerance). Since this is newly added test code, consider renaming the local test parameter to error_tolerance for readability (keeping the passed value the same).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b7d0e71 β€” renamed the parameter from error_tolerence to error_tolerance in the newly added categorical treatment test (parametrize list, function signature, and body).

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
Loading