Skip to content
Draft
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
6 changes: 3 additions & 3 deletions dowhy/api/causal_data_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def do(
variable_types[key] = self.convert_to_custom_type(all_variables[key].name)

elif len(self._obj.columns) < len(variable_types):
raise Exception("Number of variables in the DataFrame is lesser than the variable_types dict")
raise ValueError("Number of variables in the DataFrame is lesser than the variable_types dict")

if not self._sampler:
self._method = method
Expand Down Expand Up @@ -160,7 +160,7 @@ def convert_to_custom_type(self, input_type):
elif "category" in input_type:
return "d"
else:
raise Exception("{} format is not supported".format(input_type))
raise TypeError("{} format is not supported".format(input_type))

def parse_x(self, x):
if type(x) == str:
Expand All @@ -169,4 +169,4 @@ def parse_x(self, x):
return {xi: None for xi in x}, True
if type(x) == dict:
return x, False
raise Exception("x format not recognized: {}".format(type(x)))
raise TypeError("x format not recognized: {}".format(type(x)))
4 changes: 2 additions & 2 deletions dowhy/causal_identifier/id_identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def get_val(self, return_type: str):
elif return_type == "sum":
return self._sum
else:
raise Exception("Provide correct return type.")
raise ValueError("Provide correct return type. Must be 'prod' or 'sum'.")

def _print_estimator(self, prefix, estimator: Union[Dict, "IDExpression"] = None, start: bool = False):
"""
Expand Down Expand Up @@ -126,7 +126,7 @@ def identify_effect_id(
try:
tsort_node_names = OrderedSet(list(nx.topological_sort(graph))) # topological sorting of graph nodes
except nx.NetworkXUnfeasible:
raise Exception("The graph must be a directed acyclic graph (DAG).")
raise ValueError("The graph must be a directed acyclic graph (DAG).")

return __adjacency_matrix_identify_effect(
adjacency_matrix,
Expand Down
2 changes: 1 addition & 1 deletion dowhy/causal_prediction/algorithms/base_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, model, optimizer, lr, weight_decay, betas, momentum):
# Check if the optimizer is currently supported
if self.optimizer not in ["Adam", "SGD"]:
error_msg = self.optimizer + " is not implemented currently. Try Adam or SGD."
raise Exception(error_msg)
raise ValueError(error_msg)

def training_step(self, train_batch, batch_idx):
"""
Expand Down
2 changes: 1 addition & 1 deletion dowhy/do_samplers/kernel_density_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _fit_conditional(self):
)

def _infer_variable_types(self):
raise Exception(
raise NotImplementedError(
"Variable type inference not implemented. Specify variable_types={var_name: var_type}, "
"where var_type is 'o', 'c', or 'd' for ordered, continuous, or discrete, respectively."
)
Expand Down
6 changes: 3 additions & 3 deletions dowhy/do_samplers/mcmc_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def build_bayesian_network(self, g, df):
elif g.nodes()[node]["variable_type"] == "b":
g.nodes()[node]["variable"] = pm.Bernoulli("{}".format(node), logit_p=mu, observed=df[node])
else:
raise Exception("Unrecognized variable type: {}".format(g.nodes()[node]["variable_type"]))
raise ValueError("Unrecognized variable type: {}".format(g.nodes()[node]["variable_type"]))
return g

def fit_causal_model(self, g, df, data_types, initialization_trace=None):
Expand All @@ -99,7 +99,7 @@ def fit_causal_model(self, g, df, data_types, initialization_trace=None):
g = self.build_bayesian_network(g, df)
trace = pm.sample(1000, tune=1000)
else:
raise Exception("Graph is not a DAG!")
raise ValueError("Graph is not a DAG!")
return g, trace

def sample_prior_causal_model(self, g, df, data_types, initialization_trace):
Expand All @@ -111,7 +111,7 @@ def sample_prior_causal_model(self, g, df, data_types, initialization_trace):
g = self.build_bayesian_network(g, df)
trace = pm.sample_prior_predictive(1)
else:
raise Exception("Graph is not a DAG!")
raise ValueError("Graph is not a DAG!")
return g, trace

def do_x_surgery(self, g, x):
Expand Down
4 changes: 2 additions & 2 deletions dowhy/gcm/equation_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def _extract_noise_model_components(noise_eq: str) -> Tuple[str, dict]:
parsed_args = _parse_args(args)
return noise_model_name, parsed_args
else:
raise Exception("Unable to recognise the format or function specified")
raise ValueError("Unable to recognise the format or function specified")


def _extract_equation_components(equation: str) -> Tuple[str, str]:
Expand Down Expand Up @@ -185,7 +185,7 @@ def _add_undefined_nodes_info(causal_nodes_info: dict, present_nodes: list) -> N

def _check_node_redundancy(causal_nodes_info: dict, node_name: str) -> None:
if node_name in causal_nodes_info:
raise Exception(f"The node {node_name} is specified twice which is not allowed.")
raise ValueError(f"The node {node_name} is specified twice which is not allowed.")


def _sanitize_input_expression(expression: str, banned_characters: list) -> None:
Expand Down
2 changes: 1 addition & 1 deletion dowhy/utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ def parse_state(state):
return [xi for xi in state.keys()]
if not state:
return []
raise Exception("Input format for {} not recognized: {}".format(state, type(state)))
raise TypeError("Input format for {} not recognized: {}".format(state, type(state)))
6 changes: 3 additions & 3 deletions dowhy/utils/propensity_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def propensity_of_treatment_score(data, covariates, treatment, model="logistic",

def state_propensity_score(data, covariates, treatments, variable_types=None):
if len(set(covariates).intersection(treatments)) != 0:
raise Exception("Can't control for causal states. Remove treatment from covariates.")
raise ValueError("Can't control for causal states. Remove treatment from covariates.")
log_propensities = {}
for i, treatment in enumerate(treatments):
if variable_types[treatment] in ["b"]:
Expand All @@ -36,7 +36,7 @@ def state_propensity_score(data, covariates, treatments, variable_types=None):
continuous_treatment_model(data.copy(), covariates + treatments[i + 1 :], treatment, variable_types)
)
else:
raise Exception(
raise ValueError(
"Variable type {} for variable {} is not a recognized format type.".format(
variable_types[treatment], treatment
)
Expand Down Expand Up @@ -104,7 +104,7 @@ def get_type_string(variables, variable_types):
elif variable_types[variable] in ["c"]:
var_types.append("c")
else:
raise Exception(
raise ValueError(
"Variable type {} for variable {} not a recognized type.".format(variable_types[variable], variable)
)
return "".join(var_types)
Expand Down