Skip to content

Commit 6c4e43c

Browse files
committed
zero failing tests
1 parent 3757199 commit 6c4e43c

File tree

8 files changed

+182
-1627
lines changed

8 files changed

+182
-1627
lines changed

causalpy/expt_diff_in_diff.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from causalpy.data_validation import DiDDataValidator
2020
from causalpy.experiments import ExperimentalDesign
2121
from causalpy.pymc_models import PyMCModel
22-
from causalpy.utils import round_num
22+
from causalpy.utils import convert_to_string
2323

2424

2525
class DifferenceInDifferences(ExperimentalDesign, DiDDataValidator):
@@ -168,7 +168,7 @@ def __init__(
168168
# TODO: THIS IS NOT YET CORRECT
169169
self.causal_impact = (
170170
self.y_pred_treatment[1] - self.y_pred_counterfactual[0]
171-
)
171+
)[0]
172172
# ******************************************************************************
173173

174174
def plot(self, round_to=None):
@@ -197,10 +197,13 @@ def summary(self, round_to=None) -> None:
197197

198198
def _causal_impact_summary_stat(self, round_to=None) -> str:
199199
"""Computes the mean and 94% credible interval bounds for the causal impact."""
200-
percentiles = self.causal_impact.quantile([0.03, 1 - 0.03]).values
201-
ci = (
202-
"$CI_{94\\%}$"
203-
+ f"[{round_num(percentiles[0], round_to)}, {round_num(percentiles[1], round_to)}]"
204-
)
205-
causal_impact = f"{round_num(self.causal_impact.mean(), round_to)}, "
206-
return f"Causal impact = {causal_impact + ci}"
200+
201+
return f"Causal impact = {convert_to_string(self.causal_impact, round_to=round_to)}"
202+
203+
# percentiles = self.causal_impact.quantile([0.03, 1 - 0.03]).values
204+
# ci = (
205+
# "$CI_{94\\%}$"
206+
# + f"[{round_num(percentiles[0], round_to)}, {round_num(percentiles[1], round_to)}]"
207+
# )
208+
# causal_impact = f"{round_num(self.causal_impact.mean(), round_to)}, "
209+
# return f"Causal impact = {causal_impact + ci}"

causalpy/plotting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ def plot_difference_in_differences(results, round_to=None):
586586
xlim=[-0.05, 1.1],
587587
xticks=[0, 1],
588588
xticklabels=["pre", "post"],
589-
title=f"Causal impact = {round_num(results.causal_impact[0], round_to)}",
589+
title=f"Causal impact = {round_num(results.causal_impact, round_to)}",
590590
)
591591
ax.legend(fontsize=LEGEND_FONT_SIZE)
592592
return (fig, ax)

causalpy/utils.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,20 @@ def _format_sig_figs(value, default=None):
6767
return max(int(np.log10(np.abs(value))) + 1, default)
6868

6969

70-
# function `convert_to_string` which accepts either a float or an xarray object. We want
71-
# to return a string. If the input is a float, we want to return a string with 2 decimal
72-
# places. If the input is an xarray object, we want to calculate the mean and return a
73-
# string with 2 decimal places.
7470
def convert_to_string(x: Union[float, xr.DataArray], round_to=2) -> str:
71+
"""Utility function which takes in nunmeric inputs and returns a string."""
7572
if isinstance(x, float):
73+
# In the case of a float, we return the number rounded to 2 decimal places
7674
return f"{x:.2f}"
77-
else:
75+
elif isinstance(x, xr.DataArray):
76+
# In the case of an xarray object, we return the mean and 94% CI
7877
percentiles = x.quantile([0.03, 1 - 0.03]).values
7978
ci = (
8079
r"$CI_{94\%}$"
8180
+ f"[{round_num(percentiles[0], round_to)}, {round_num(percentiles[1], round_to)}]"
8281
)
8382
return f"{x.mean().values:.2f}" + ci
83+
else:
84+
raise ValueError(
85+
"Type not supported. Please provide a float or an xarray object."
86+
)

docs/source/_static/interrogate_badge.svg

Lines changed: 3 additions & 3 deletions
Loading

docs/source/notebooks/REFACTOR.ipynb

Lines changed: 135 additions & 1566 deletions
Large diffs are not rendered by default.

docs/source/notebooks/did_pymc.ipynb

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

docs/source/notebooks/did_pymc_banks.ipynb

Lines changed: 7 additions & 7 deletions
Large diffs are not rendered by default.

docs/source/notebooks/did_skl.ipynb

Lines changed: 13 additions & 33 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)