Skip to content

Commit eff405d

Browse files
committed
formatting
1 parent f3453ce commit eff405d

2 files changed

Lines changed: 37 additions & 26 deletions

File tree

causalml/metrics/visualize.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -988,14 +988,16 @@ def _compute_rate(df_, model_col, outcome_col, treatment_col, weighting):
988988
ci_upper = point + z_crit * se
989989
z_stat = point / se if se > 0 else np.inf
990990
p_value = 2 * (1 - stats.norm.cdf(abs(z_stat)))
991-
results.append({
992-
"model": model,
993-
"rate": point,
994-
"se": se,
995-
"ci_lower": ci_lower,
996-
"ci_upper": ci_upper,
997-
"p_value": p_value,
998-
})
991+
results.append(
992+
{
993+
"model": model,
994+
"rate": point,
995+
"se": se,
996+
"ci_lower": ci_lower,
997+
"ci_upper": ci_upper,
998+
"p_value": p_value,
999+
}
1000+
)
9991001

10001002
return pd.DataFrame(results).set_index("model")
10011003

tests/test_visualize.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,15 @@ def test_plot_tmlegain(generate_regression_data, monkeypatch):
7777
def test_rate_score_basic():
7878
np.random.seed(42)
7979
n = 500
80-
df = pd.DataFrame({
81-
"y": np.random.binomial(1, 0.5, n),
82-
"w": np.random.binomial(1, 0.5, n),
83-
"tau": np.zeros(n),
84-
"model_good": np.random.normal(1, 1, n),
85-
"model_random": np.random.normal(0, 1, n),
86-
})
80+
df = pd.DataFrame(
81+
{
82+
"y": np.random.binomial(1, 0.5, n),
83+
"w": np.random.binomial(1, 0.5, n),
84+
"tau": np.zeros(n),
85+
"model_good": np.random.normal(1, 1, n),
86+
"model_random": np.random.normal(0, 1, n),
87+
}
88+
)
8789

8890
result = rate_score(df)
8991
assert isinstance(result, pd.Series)
@@ -94,13 +96,15 @@ def test_rate_score_basic():
9496
def test_rate_score_with_ci():
9597
np.random.seed(42)
9698
n = 500
97-
df = pd.DataFrame({
98-
"y": np.random.binomial(1, 0.5, n),
99-
"w": np.random.binomial(1, 0.5, n),
100-
"tau": np.zeros(n),
101-
"model_good": np.random.normal(1, 1, n),
102-
"model_random": np.random.normal(0, 1, n),
103-
})
99+
df = pd.DataFrame(
100+
{
101+
"y": np.random.binomial(1, 0.5, n),
102+
"w": np.random.binomial(1, 0.5, n),
103+
"tau": np.zeros(n),
104+
"model_good": np.random.normal(1, 1, n),
105+
"model_random": np.random.normal(0, 1, n),
106+
}
107+
)
104108

105109
result = rate_score(df, return_ci=True, n_bootstrap=50)
106110
assert isinstance(result, pd.DataFrame)
@@ -111,14 +115,19 @@ def test_rate_score_with_ci():
111115

112116

113117
def test_rate_score_invalid_weighting():
114-
df = pd.DataFrame({
115-
"y": [1, 0, 1], "w": [1, 0, 1], "tau": [0.1, 0.2, 0.3], "model": [0.5, 0.3, 0.8]
116-
})
118+
df = pd.DataFrame(
119+
{
120+
"y": [1, 0, 1],
121+
"w": [1, 0, 1],
122+
"tau": [0.1, 0.2, 0.3],
123+
"model": [0.5, 0.3, 0.8],
124+
}
125+
)
117126
with pytest.raises(ValueError, match="weighting must be"):
118127
rate_score(df, weighting="invalid")
119128

120129

121130
def test_rate_score_no_model_cols():
122131
df = pd.DataFrame({"y": [1, 0], "w": [1, 0], "tau": [0.1, 0.2]})
123132
with pytest.raises(ValueError, match="No model prediction columns"):
124-
rate_score(df)
133+
rate_score(df)

0 commit comments

Comments
 (0)