Skip to content

Commit 42bc17c

Browse files
committed
docs: clarify DiD predict support contract
1 parent b5a5452 commit 42bc17c

3 files changed

Lines changed: 38 additions & 7 deletions

File tree

diff_diff/estimators.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -975,26 +975,39 @@ def _validate_data(
975975

976976
def predict(self, data: pd.DataFrame) -> np.ndarray:
977977
"""
978-
Predict outcomes using fitted model.
978+
Predict outcomes using the fitted model.
979+
980+
Out-of-sample prediction is intentionally unsupported pending a broader
981+
post-estimation design for estimator result objects. For fitted
982+
training-data predictions, use ``results_.fitted_values`` after
983+
:meth:`fit`.
979984
980985
Parameters
981986
----------
982987
data : pd.DataFrame
983-
DataFrame with same structure as training data.
988+
Candidate prediction data. Currently unused because out-of-sample
989+
prediction is unsupported.
984990
985991
Returns
986992
-------
987993
np.ndarray
988994
Predicted values.
995+
996+
Raises
997+
------
998+
RuntimeError
999+
If called before :meth:`fit`.
1000+
NotImplementedError
1001+
Always raised after fitting until the broader post-estimation
1002+
prediction contract is designed.
9891003
"""
9901004
if not self.is_fitted_:
9911005
raise RuntimeError("Model must be fitted before calling predict()")
9921006

993-
# This is a placeholder - would need to store column names
994-
# for full implementation
9951007
raise NotImplementedError(
996-
"predict() is not yet implemented. "
997-
"Use results_.fitted_values for training data predictions."
1008+
"out-of-sample predict() is unsupported pending a broader "
1009+
"post-estimation design. Use results_.fitted_values for fitted "
1010+
"training-data predictions."
9981011
)
9991012

10001013
def get_params(self) -> Dict[str, Any]:

docs/api/estimators.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ DifferenceInDifferences (alias: ``DiD``)
3030

3131
Basic 2x2 DiD estimator.
3232

33+
``DifferenceInDifferences.predict()`` is present for sklearn-like
34+
discoverability, but out-of-sample prediction is not currently supported. Use
35+
``results_.fitted_values`` for fitted training-data predictions until a broader
36+
post-estimation result-object contract is designed.
37+
3338
.. autoclass:: diff_diff.DifferenceInDifferences
3439
:no-index:
3540
:members:
@@ -42,6 +47,7 @@ Basic 2x2 DiD estimator.
4247
.. autosummary::
4348

4449
~DifferenceInDifferences.fit
50+
~DifferenceInDifferences.predict
4551
~DifferenceInDifferences.get_params
4652
~DifferenceInDifferences.set_params
4753

@@ -84,4 +90,3 @@ Synthetic control combined with DiD (Arkhangelsky et al. 2021).
8490
:undoc-members:
8591
:show-inheritance:
8692
:inherited-members:
87-

tests/test_methodology_did.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,3 +1549,16 @@ def test_residuals_and_fitted_values(self):
15491549

15501550
assert np.allclose(reconstructed, original), \
15511551
"Residuals + fitted should equal original outcome"
1552+
1553+
def test_predict_contract_points_to_fitted_values(self):
1554+
"""predict() is intentionally unsupported until post-estimation is designed."""
1555+
data, _ = generate_hand_calculable_data()
1556+
1557+
did = DifferenceInDifferences()
1558+
did.fit(data, outcome='outcome', treatment='treated', time='post')
1559+
1560+
with pytest.raises(
1561+
NotImplementedError,
1562+
match="out-of-sample.*post-estimation.*results_\\.fitted_values",
1563+
):
1564+
did.predict(data)

0 commit comments

Comments
 (0)