Skip to content

Commit da1e25f

Browse files
jeongyoonleeclaude
andcommitted
Add ttest criterion regression test for inf predictions (#589)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9caf6c2 commit da1e25f

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

tests/test_causal_trees.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,26 @@ def test_CausalRandomForestRegressor_no_inf_predictions():
299299
preds = model.predict(X=X)
300300

301301
assert np.all(np.isfinite(preds)), "Predictions contain inf or NaN values"
302+
303+
304+
def test_CausalRandomForestRegressor_no_inf_predictions_ttest():
305+
"""Test that CausalRandomForestRegressor with criterion='ttest' does not
306+
predict inf values when some tree splits have zero-count
307+
treatment/control groups (#589)."""
308+
np.random.seed(RANDOM_SEED)
309+
n = 100
310+
X = np.random.randn(n, 5)
311+
treatment = np.array([0] * 90 + [1] * 10)
312+
y = np.random.randn(n)
313+
314+
model = CausalRandomForestRegressor(
315+
criterion="ttest",
316+
control_name=0,
317+
n_estimators=10,
318+
min_samples_leaf=1,
319+
random_state=RANDOM_SEED,
320+
)
321+
model.fit(X=X, treatment=treatment, y=y)
322+
preds = model.predict(X=X)
323+
324+
assert np.all(np.isfinite(preds)), "Predictions contain inf or NaN values"

0 commit comments

Comments
 (0)