Skip to content

Commit 0eefd4b

Browse files
committed
Patsy interaction treatment terms can now be read
1 parent 9abdcbc commit 0eefd4b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

causal_testing/testing/estimators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,15 +352,15 @@ def estimate_coefficient(self) -> float:
352352
model = self._run_linear_regression()
353353
newline = "\n"
354354
treatment = [self.treatment]
355-
if str(self.df.dtypes[self.treatment]) == "object":
355+
if self.treatment in self.df.dtypes and str(self.df.dtypes[self.treatment]) == "object":
356356
design_info = dmatrix(self.formula.split("~")[1], self.df).design_info
357357
treatment = design_info.column_names[design_info.term_name_slices[self.treatment]]
358358
assert set(treatment).issubset(
359359
model.params.index.tolist()
360360
), f"{treatment} not in\n{' ' + str(model.params.index).replace(newline, newline + ' ')}"
361361
unit_effect = model.params[treatment] # Unit effect is the coefficient of the treatment
362362
[ci_low, ci_high] = self._get_confidence_intervals(model, treatment)
363-
if str(self.df.dtypes[self.treatment]) != "object":
363+
if self.treatment not in self.df.dtypes or str(self.df.dtypes[self.treatment]) != "object":
364364
unit_effect = unit_effect[0]
365365
ci_low = ci_low[0]
366366
ci_high = ci_high[0]

0 commit comments

Comments
 (0)