Skip to content

Commit 10690c6

Browse files
committed
Add tests for EventStudy effect_summary method
Introduces integration tests for the EventStudy.effect_summary method using both PyMC and sklearn models. Tests verify the returned EffectSummary object, its table and text attributes, and key output elements.
1 parent af32b60 commit 10690c6

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

causalpy/tests/test_event_study.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,3 +476,67 @@ def test_event_study_all_control_units():
476476

477477
# Check that result was created
478478
assert isinstance(result, cp.EventStudy)
479+
480+
481+
# ============================================================================
482+
# Tests for effect_summary
483+
# ============================================================================
484+
485+
486+
@pytest.mark.integration
487+
def test_event_study_pymc_effect_summary(mock_pymc_sample):
488+
"""Test EventStudy effect_summary method with PyMC model."""
489+
df = generate_event_study_data(n_units=20, n_time=20, treatment_time=10, seed=42)
490+
491+
result = cp.EventStudy(
492+
df,
493+
formula="y ~ C(unit) + C(time)",
494+
unit_col="unit",
495+
time_col="time",
496+
treat_time_col="treat_time",
497+
event_window=(-3, 3),
498+
reference_event_time=-1,
499+
model=cp.pymc_models.LinearRegression(sample_kwargs=sample_kwargs),
500+
)
501+
502+
# Test effect_summary returns EffectSummary with table and text
503+
effect = result.effect_summary()
504+
assert isinstance(effect.table, pd.DataFrame)
505+
assert isinstance(effect.text, str)
506+
assert "event_time" in effect.table.columns
507+
assert "mean" in effect.table.columns
508+
509+
# Check prose mentions key elements
510+
assert "Event study" in effect.text
511+
assert "k=" in effect.text
512+
513+
# Test with include_pretrend_check=False
514+
effect_no_pretrend = result.effect_summary(include_pretrend_check=False)
515+
assert isinstance(effect_no_pretrend.text, str)
516+
517+
518+
def test_event_study_sklearn_effect_summary():
519+
"""Test EventStudy effect_summary method with sklearn model."""
520+
df = generate_event_study_data(n_units=20, n_time=20, treatment_time=10, seed=42)
521+
522+
result = cp.EventStudy(
523+
df,
524+
formula="y ~ C(unit) + C(time)",
525+
unit_col="unit",
526+
time_col="time",
527+
treat_time_col="treat_time",
528+
event_window=(-3, 3),
529+
reference_event_time=-1,
530+
model=LinearRegression(),
531+
)
532+
533+
# Test effect_summary returns EffectSummary with table and text
534+
effect = result.effect_summary()
535+
assert isinstance(effect.table, pd.DataFrame)
536+
assert isinstance(effect.text, str)
537+
assert "event_time" in effect.table.columns
538+
assert "mean" in effect.table.columns
539+
540+
# Check prose mentions key elements
541+
assert "Event study" in effect.text
542+
assert "k=" in effect.text

0 commit comments

Comments
 (0)