Skip to content

Commit 8587b35

Browse files
igerberclaude
andcommitted
fix(docs): unwrap load_prop99 docstring bullet (Sphinx -W) + extend doc-snippet mock loaders with prop99/walmart
The doc-snippets harness replaces sys.modules['diff_diff.datasets'] with a mock module; the new loaders' snippets need mock counterparts there. The wrapped Returns bullet in load_prop99 broke the -W docs build (unexpected indentation). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FZK3FD9jxWGxBrPDw5APSg
1 parent 4692e72 commit 8587b35

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

diff_diff/datasets.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -828,8 +828,7 @@ def load_prop99(force_download: bool = False) -> pd.DataFrame:
828828
Panel dataset with columns:
829829
- state : str - State name
830830
- year : int - Year (1970-2000)
831-
- first_year : int - Year treatment began (1989 for California,
832-
0 = never treated)
831+
- first_year : int - Treatment start year (1989 for California, 0 = never)
833832
- lcigsale : float - Log per capita cigarette sales (packs)
834833
- treated : int - 1 if treatment in effect, 0 otherwise
835834
- cohort : int - Alias for first_year

tests/test_doc_snippets.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,51 @@ def _mock_load_mpdta(**kwargs):
287287
}
288288
)
289289

290+
def _mock_load_prop99(**kwargs):
291+
states = ["California"] + [f"State{i:02d}" for i in range(2, 11)]
292+
years = list(range(1980, 1996))
293+
rows = [(s, y) for s in states for y in years]
294+
fy = [1989 if r[0] == "California" else 0 for r in rows]
295+
return pd.DataFrame(
296+
{
297+
"state": [r[0] for r in rows],
298+
"year": [r[1] for r in rows],
299+
"first_year": fy,
300+
"lcigsale": rng.normal(4.6, 0.1, len(rows)),
301+
"treated": [1 if f and r[1] >= f else 0 for f, r in zip(fy, rows)],
302+
"cohort": fy,
303+
}
304+
)
305+
306+
def _mock_load_walmart(**kwargs):
307+
counties = list(range(1, 21))
308+
years = list(range(1985, 1996))
309+
rows = [(c, y) for c in counties for y in years]
310+
n = len(rows)
311+
cohort_of = {c: (0 if c <= 8 else [1988, 1990, 1992][c % 3]) for c in counties}
312+
fy = [cohort_of[r[0]] for r in rows]
313+
return pd.DataFrame(
314+
{
315+
"cid": [r[0] for r in rows],
316+
"year": [r[1] for r in rows],
317+
"first_year": fy,
318+
"log_retail_emp": rng.normal(7.5, 0.5, n),
319+
"log_wholesale_emp": rng.normal(6.5, 0.5, n),
320+
"x1": rng.uniform(0.05, 0.3, n),
321+
"x2": rng.uniform(0.5, 0.85, n),
322+
"x3": rng.uniform(0.05, 0.4, n),
323+
"treated": [1 if f and r[1] >= f else 0 for f, r in zip(fy, rows)],
324+
"cohort": fy,
325+
}
326+
)
327+
290328
_dataset_dispatch = {
291329
"card_krueger": _mock_load_card_krueger,
292330
"castle_doctrine": _mock_load_castle_doctrine,
293331
"divorce_laws": _mock_load_divorce_laws,
294332
"mpdta": _mock_load_mpdta,
333+
"prop99": _mock_load_prop99,
334+
"walmart": _mock_load_walmart,
295335
}
296336

297337
def _mock_load_dataset(name, **kwargs):
@@ -305,6 +345,8 @@ def _mock_list_datasets():
305345
"castle_doctrine": "Castle Doctrine laws - staggered adoption",
306346
"divorce_laws": "Unilateral divorce laws - staggered adoption",
307347
"mpdta": "Minimum wage panel data - simulated CS example",
348+
"prop99": "California Prop 99 smoking panel - single treated unit",
349+
"walmart": "Walmart entry county panel - staggered adoption",
308350
}
309351

310352
# Inject mocks into namespace so `from diff_diff.datasets import ...` works
@@ -315,6 +357,8 @@ def _mock_list_datasets():
315357
mock_datasets_mod.load_castle_doctrine = _mock_load_castle_doctrine
316358
mock_datasets_mod.load_divorce_laws = _mock_load_divorce_laws
317359
mock_datasets_mod.load_mpdta = _mock_load_mpdta
360+
mock_datasets_mod.load_prop99 = _mock_load_prop99
361+
mock_datasets_mod.load_walmart = _mock_load_walmart
318362
mock_datasets_mod.load_dataset = _mock_load_dataset
319363
mock_datasets_mod.list_datasets = _mock_list_datasets
320364
import sys
@@ -327,6 +371,8 @@ def _mock_list_datasets():
327371
ns["load_castle_doctrine"] = _mock_load_castle_doctrine
328372
ns["load_divorce_laws"] = _mock_load_divorce_laws
329373
ns["load_mpdta"] = _mock_load_mpdta
374+
ns["load_prop99"] = _mock_load_prop99
375+
ns["load_walmart"] = _mock_load_walmart
330376
ns["load_dataset"] = _mock_load_dataset
331377
ns["list_datasets"] = _mock_list_datasets
332378

0 commit comments

Comments
 (0)