Skip to content
Open
6 changes: 3 additions & 3 deletions dowhy/causal_estimators/distance_matching_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ def fit(self, data: pd.DataFrame, effect_modifier_names: Optional[List[str]] = N
# Check if the treatment is one-dimensional
if len(self._target_estimand.treatment_variable) > 1:
error_msg = str(self.__class__) + "cannot handle more than one treatment variable"
Comment thread
emrekiciman marked this conversation as resolved.
Outdated
raise Exception(error_msg)
raise ValueError(error_msg)
# Checking if the treatment is binary
if not data[self._target_estimand.treatment_variable[0]].isin([0, 1]).all():
error_msg = "Distance Matching method is applicable only for binary treatments."
self.logger.error(error_msg)
raise Exception(error_msg)
raise ValueError(error_msg)

self.logger.debug("Adjustment set variables used:" + ",".join(self._target_estimand.get_adjustment_set()))

Expand All @@ -160,7 +160,7 @@ def fit(self, data: pd.DataFrame, effect_modifier_names: Optional[List[str]] = N
self._observed_common_causes = None
error_msg = "No common causes/confounders present. Distance matching methods are not applicable"
self.logger.error(error_msg)
raise Exception(error_msg)
raise ValueError(error_msg)

self.symbolic_estimator = self.construct_symbolic_estimator(self._target_estimand)
self.logger.info(self.symbolic_estimator)
Expand Down
6 changes: 3 additions & 3 deletions dowhy/causal_estimators/doubly_robust_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ def fit(
# Validate target estimand
if len(self._target_estimand.treatment_variable) > 1:
error_msg = str(self.__class__) + " cannot handle more than one treatment variable"
raise Exception(error_msg)
raise ValueError(error_msg)
if len(self._target_estimand.outcome_variable) > 1:
error_msg = str(self.__class__) + " cannot handle more than one outcome variable"
raise Exception(error_msg)
raise ValueError(error_msg)
if self._target_estimand.identifier_method not in ["backdoor", "general_adjustment"]:
error_msg = str(self.__class__) + " only supports covariate adjustment identifiers"
raise Exception(error_msg)
raise ValueError(error_msg)
if effect_modifier_names and (len(effect_modifier_names) > 0):
# TODO: Add support for effect modifiers in the Doubly Robust Estimator
raise NotImplementedError("Effect Modifiers not supported yet for " + str(self.__class__))
Expand Down
6 changes: 3 additions & 3 deletions dowhy/causal_estimators/propensity_score_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,18 @@ def fit(
self._observed_common_causes = None
error_msg = "No common causes/confounders present. Propensity score based methods are not applicable"
self.logger.error(error_msg)
raise Exception(error_msg)
raise ValueError(error_msg)

# Check if the treatment is one-dimensional
if len(self._target_estimand.treatment_variable) > 1:
error_msg = str(self.__class__) + "cannot handle more than one treatment variable"
Comment thread
emrekiciman marked this conversation as resolved.
Outdated
raise Exception(error_msg)
raise ValueError(error_msg)
# Checking if the treatment is binary
treatment_values = data[self._target_estimand.treatment_variable[0]].astype(int).unique()
if any([v not in [0, 1] for v in treatment_values]):
error_msg = "Propensity score methods are applicable only for binary treatments"
self.logger.error(error_msg)
raise Exception(error_msg)
raise ValueError(error_msg)

if self.propensity_score_column not in data:
if self.propensity_score_model is None:
Expand Down
4 changes: 2 additions & 2 deletions dowhy/causal_estimators/two_stage_regression_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def __init__(
# Check if the treatment is one-dimensional
if len(self._target_estimand.treatment_variable) > 1:
error_msg = str(self.__class__) + "cannot handle more than one treatment variable"
Comment thread
emrekiciman marked this conversation as resolved.
Outdated
raise Exception(error_msg)
raise ValueError(error_msg)
modified_target_estimand = copy.deepcopy(self._target_estimand)
modified_target_estimand.identifier_method = "backdoor"
modified_target_estimand.backdoor_variables = self._target_estimand.mediation_first_stage_confounders
Expand Down Expand Up @@ -173,7 +173,7 @@ def fit(

if len(self._target_estimand.treatment_variable) > 1:
error_msg = str(self.__class__) + "cannot handle more than one treatment variable"
Comment thread
emrekiciman marked this conversation as resolved.
Outdated
raise Exception(error_msg)
raise ValueError(error_msg)

if self._target_estimand.identifier_method == "frontdoor":
self.logger.debug("Front-door variable used:" + ",".join(self._target_estimand.get_frontdoor_variables()))
Expand Down
10 changes: 3 additions & 7 deletions tests/causal_estimators/test_two_stage_regression_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ def test_frontdoor_estimator(self):
target "X"
]
]
""".replace(
"\n", ""
)
""".replace("\n", "")

N_SAMPLES = 10000
# Generate the data
Expand Down Expand Up @@ -161,7 +159,7 @@ def test_frontdoor_estimator(self):
)
def test_frontdoor_num_variables_error(self, Estimator, num_treatments, num_frontdoor_variables):
estimator_tester = SimpleEstimator(error_tolerance=0, Estimator=Estimator, identifier_method="frontdoor")
with pytest.raises((ValueError, Exception)):
with pytest.raises(ValueError):
estimator_tester.average_treatment_effect_testsuite(
num_common_causes=[1, 1],
num_instruments=[0, 0],
Expand Down Expand Up @@ -209,9 +207,7 @@ def _make_mediation_data(n=2000, seed=42):
edge [ source "X" target "Y" ]
edge [ source "M" target "Y" ]
]
""".replace(
"\n", " "
)
""".replace("\n", " ")


class TestTwoStageRegressionMediationNIE:
Expand Down
Loading