Skip to content

Commit ec34beb

Browse files
igerberclaude
andcommitted
Address PR #351 R11 P3: document return_convergence tuple return
R11 CI review flagged that compute_time_weights and compute_sdid_unit _weights describe the new return_convergence parameter but their Returns sections still advertise only np.ndarray, not the tuple return. Update both docstrings to mirror _sc_weight_fw's union-return shape: Returns now read "np.ndarray or Tuple[np.ndarray, bool]" with an explicit description of the two-pass AND convergence flag (True iff both pre-sparsify and main FW passes hit the min-decrease break; False if either hit max_iter). Also promote the return_convergence kwarg description from the implementation-detail placement to the main Parameters block with the same contract note as _sc_weight_fw so standalone callers see the legacy-ABI preservation guarantee and the Rust top-level fast-path skip. Docs-only change; no code or test changes. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 5eadcb6 commit ec34beb

1 file changed

Lines changed: 28 additions & 4 deletions

File tree

diff_diff/utils.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,11 +1503,23 @@ def compute_time_weights(
15031503
through; this matches R's ``synthdid::bootstrap_sample`` shape
15041504
(which passes ``weights$lambda`` as FW init per draw). Used by
15051505
``SyntheticDiD._bootstrap_se`` on the refit loop.
1506+
return_convergence : bool, default False
1507+
If True, returns a tuple ``(weights, converged)`` where ``converged``
1508+
is the AND of the first-pass and second-pass convergence flags from
1509+
the underlying ``_sc_weight_fw`` calls (True iff the min-decrease
1510+
criterion fired on BOTH passes; False if either hit ``max_iter``).
1511+
Setting this flag also forces the Python two-pass dispatcher even
1512+
when ``init_weights`` is None, because the Rust top-level fast-path
1513+
is silent on non-convergence. Used by SDID bootstrap to surface
1514+
per-draw FW non-convergence explicitly; standalone callers can
1515+
leave this at the default to preserve the legacy ABI.
15061516
15071517
Returns
15081518
-------
1509-
np.ndarray
1510-
Time weights of shape (n_pre,) on the simplex.
1519+
np.ndarray or Tuple[np.ndarray, bool]
1520+
Time weights of shape (n_pre,) on the simplex. With
1521+
``return_convergence=True``, additionally the two-pass convergence
1522+
flag (as described above).
15111523
"""
15121524
if Y_post_control.shape[0] == 0:
15131525
raise ValueError(
@@ -1636,11 +1648,23 @@ def compute_sdid_unit_weights(
16361648
through; this matches R's ``synthdid::bootstrap_sample`` shape
16371649
(which passes ``sum_normalize(weights$omega[...])`` as FW init per
16381650
draw). Used by ``SyntheticDiD._bootstrap_se`` on the refit loop.
1651+
return_convergence : bool, default False
1652+
If True, returns a tuple ``(weights, converged)`` where ``converged``
1653+
is the AND of the first-pass and second-pass convergence flags from
1654+
the underlying ``_sc_weight_fw`` calls (True iff the min-decrease
1655+
criterion fired on BOTH passes; False if either hit ``max_iter``).
1656+
Setting this flag also forces the Python two-pass dispatcher even
1657+
when ``init_weights`` is None, because the Rust top-level fast-path
1658+
is silent on non-convergence. Used by SDID bootstrap to surface
1659+
per-draw FW non-convergence explicitly; standalone callers can
1660+
leave this at the default to preserve the legacy ABI.
16391661
16401662
Returns
16411663
-------
1642-
np.ndarray
1643-
Unit weights of shape (n_control,) on the simplex.
1664+
np.ndarray or Tuple[np.ndarray, bool]
1665+
Unit weights of shape (n_control,) on the simplex. With
1666+
``return_convergence=True``, additionally the two-pass convergence
1667+
flag (as described above).
16441668
"""
16451669
n_control = Y_pre_control.shape[1]
16461670

0 commit comments

Comments
 (0)