factor-factory 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- factor_factory-1.0.0/.claude/agents/contract-auditor.md +46 -0
- factor_factory-1.0.0/.claude/agents/engine-reviewer.md +37 -0
- factor_factory-1.0.0/.claude/commands/add-engine.md +27 -0
- factor_factory-1.0.0/.claude/commands/bump.md +24 -0
- factor_factory-1.0.0/.claude/commands/contract-check.md +9 -0
- factor_factory-1.0.0/.claude/commands/engine-status.md +17 -0
- factor_factory-1.0.0/.claude/commands/release-check.md +16 -0
- factor_factory-1.0.0/.claude/launch.json +22 -0
- factor_factory-1.0.0/.claude/skills/engine-protocol.md +35 -0
- factor_factory-1.0.0/.claude/skills/fixture-parity.md +68 -0
- factor_factory-1.0.0/.claude/skills/piggyback-first.md +46 -0
- factor_factory-1.0.0/.claude/skills/release-bump.md +59 -0
- factor_factory-1.0.0/.claude/skills/tearsheet-json-contract.md +67 -0
- factor_factory-1.0.0/.github/PULL_REQUEST_TEMPLATE.md +41 -0
- factor_factory-1.0.0/.github/workflows/ci.yml +96 -0
- factor_factory-1.0.0/.github/workflows/release.yml +78 -0
- factor_factory-1.0.0/.gitignore +32 -0
- factor_factory-1.0.0/.readthedocs.yaml +24 -0
- factor_factory-1.0.0/AGENTS.md +60 -0
- factor_factory-1.0.0/CHANGELOG.md +426 -0
- factor_factory-1.0.0/CITATION.cff +35 -0
- factor_factory-1.0.0/CLAUDE.md +95 -0
- factor_factory-1.0.0/CONTRIBUTING.md +84 -0
- factor_factory-1.0.0/LICENSE +21 -0
- factor_factory-1.0.0/Makefile +77 -0
- factor_factory-1.0.0/PKG-INFO +372 -0
- factor_factory-1.0.0/README.md +241 -0
- factor_factory-1.0.0/docs/conf.py +144 -0
- factor_factory-1.0.0/docs/cookbook/did-callaway-santanna.md +44 -0
- factor_factory-1.0.0/docs/cookbook/did-twfe.md +47 -0
- factor_factory-1.0.0/docs/cookbook/event-study-market-adjusted.md +31 -0
- factor_factory-1.0.0/docs/cookbook/mediation-four-way.md +73 -0
- factor_factory-1.0.0/docs/cookbook/rdd.md +50 -0
- factor_factory-1.0.0/docs/cookbook/scm.md +27 -0
- factor_factory-1.0.0/docs/cookbook/sdid.md +51 -0
- factor_factory-1.0.0/docs/cookbook/survival-cox.md +36 -0
- factor_factory-1.0.0/docs/cookbook/survival-km.md +33 -0
- factor_factory-1.0.0/docs/design-contracts.md +251 -0
- factor_factory-1.0.0/docs/development/adding-an-engine.md +77 -0
- factor_factory-1.0.0/docs/development/contributing.md +8 -0
- factor_factory-1.0.0/docs/development/dev-setup.md +53 -0
- factor_factory-1.0.0/docs/development/releasing.md +67 -0
- factor_factory-1.0.0/docs/development/testing.md +86 -0
- factor_factory-1.0.0/docs/getting-started.md +407 -0
- factor_factory-1.0.0/docs/index.md +98 -0
- factor_factory-1.0.0/docs/jellycell-integration.md +212 -0
- factor_factory-1.0.0/docs/migration/v0-to-v1.md +98 -0
- factor_factory-1.0.0/docs/og_context/00_design_rationale.md +182 -0
- factor_factory-1.0.0/docs/og_context/01_architecture.md +258 -0
- factor_factory-1.0.0/docs/og_context/02_implementation_plan.md +251 -0
- factor_factory-1.0.0/docs/og_context/03_specs/diagnostics_contract.md +229 -0
- factor_factory-1.0.0/docs/og_context/03_specs/engine_protocol.md +292 -0
- factor_factory-1.0.0/docs/og_context/03_specs/jellycell_integration.md +279 -0
- factor_factory-1.0.0/docs/og_context/03_specs/panel_contract.md +261 -0
- factor_factory-1.0.0/docs/og_context/03_specs/tidy_contract.md +236 -0
- factor_factory-1.0.0/docs/og_context/04_downstream_changes.md +248 -0
- factor_factory-1.0.0/docs/og_context/05_rfc_template.md +125 -0
- factor_factory-1.0.0/docs/og_context/06_post_v0.1_roadmap.md +529 -0
- factor_factory-1.0.0/docs/og_context/README.md +80 -0
- factor_factory-1.0.0/docs/reference/architecture.md +52 -0
- factor_factory-1.0.0/docs/reference/contracts.md +166 -0
- factor_factory-1.0.0/docs/reference/piggyback-map.md +62 -0
- factor_factory-1.0.0/docs/references.bib +178 -0
- factor_factory-1.0.0/docs/supported-domains.md +195 -0
- factor_factory-1.0.0/factor_factory/__init__.py +32 -0
- factor_factory-1.0.0/factor_factory/__main__.py +46 -0
- factor_factory-1.0.0/factor_factory/_version.py +1 -0
- factor_factory-1.0.0/factor_factory/diagnostics/__init__.py +13 -0
- factor_factory-1.0.0/factor_factory/diagnostics/assertions.py +49 -0
- factor_factory-1.0.0/factor_factory/diagnostics/balance.py +99 -0
- factor_factory-1.0.0/factor_factory/diagnostics/residuals.py +96 -0
- factor_factory-1.0.0/factor_factory/diagnostics/trends.py +80 -0
- factor_factory-1.0.0/factor_factory/engines/__init__.py +29 -0
- factor_factory-1.0.0/factor_factory/engines/_base.py +12 -0
- factor_factory-1.0.0/factor_factory/engines/_registry.py +37 -0
- factor_factory-1.0.0/factor_factory/engines/changepoint/__init__.py +64 -0
- factor_factory-1.0.0/factor_factory/engines/changepoint/_base.py +59 -0
- factor_factory-1.0.0/factor_factory/engines/changepoint/ruptures_adapter.py +78 -0
- factor_factory-1.0.0/factor_factory/engines/climate/__init__.py +179 -0
- factor_factory-1.0.0/factor_factory/engines/did/__init__.py +126 -0
- factor_factory-1.0.0/factor_factory/engines/did/_base.py +82 -0
- factor_factory-1.0.0/factor_factory/engines/did/borusyak_jaravel_spiess.py +166 -0
- factor_factory-1.0.0/factor_factory/engines/did/callaway_santanna.py +199 -0
- factor_factory-1.0.0/factor_factory/engines/did/sun_abraham.py +152 -0
- factor_factory-1.0.0/factor_factory/engines/did/twfe.py +87 -0
- factor_factory-1.0.0/factor_factory/engines/diffusion/__init__.py +180 -0
- factor_factory-1.0.0/factor_factory/engines/dml/__init__.py +69 -0
- factor_factory-1.0.0/factor_factory/engines/dml/_base.py +69 -0
- factor_factory-1.0.0/factor_factory/engines/dml/plr.py +85 -0
- factor_factory-1.0.0/factor_factory/engines/event_study/__init__.py +80 -0
- factor_factory-1.0.0/factor_factory/engines/event_study/_base.py +102 -0
- factor_factory-1.0.0/factor_factory/engines/event_study/fama_french.py +281 -0
- factor_factory-1.0.0/factor_factory/engines/event_study/market_adjusted.py +136 -0
- factor_factory-1.0.0/factor_factory/engines/hawkes/__init__.py +191 -0
- factor_factory-1.0.0/factor_factory/engines/het_te/__init__.py +74 -0
- factor_factory-1.0.0/factor_factory/engines/het_te/_base.py +77 -0
- factor_factory-1.0.0/factor_factory/engines/het_te/bcf.py +130 -0
- factor_factory-1.0.0/factor_factory/engines/het_te/causal_forest.py +106 -0
- factor_factory-1.0.0/factor_factory/engines/inequality/__init__.py +167 -0
- factor_factory-1.0.0/factor_factory/engines/mediation/__init__.py +85 -0
- factor_factory-1.0.0/factor_factory/engines/mediation/_base.py +234 -0
- factor_factory-1.0.0/factor_factory/engines/mediation/four_way.py +269 -0
- factor_factory-1.0.0/factor_factory/engines/panel_reg/__init__.py +73 -0
- factor_factory-1.0.0/factor_factory/engines/panel_reg/_base.py +71 -0
- factor_factory-1.0.0/factor_factory/engines/panel_reg/pyfixest_adapter.py +79 -0
- factor_factory-1.0.0/factor_factory/engines/rdd/__init__.py +85 -0
- factor_factory-1.0.0/factor_factory/engines/rdd/_base.py +93 -0
- factor_factory-1.0.0/factor_factory/engines/rdd/rd_robust.py +130 -0
- factor_factory-1.0.0/factor_factory/engines/reporting_bias/__init__.py +214 -0
- factor_factory-1.0.0/factor_factory/engines/scm/__init__.py +71 -0
- factor_factory-1.0.0/factor_factory/engines/scm/_base.py +70 -0
- factor_factory-1.0.0/factor_factory/engines/scm/augmented.py +129 -0
- factor_factory-1.0.0/factor_factory/engines/scm/matrix_completion.py +123 -0
- factor_factory-1.0.0/factor_factory/engines/scm/pysyncon_adapter.py +116 -0
- factor_factory-1.0.0/factor_factory/engines/sdid/__init__.py +82 -0
- factor_factory-1.0.0/factor_factory/engines/sdid/_base.py +141 -0
- factor_factory-1.0.0/factor_factory/engines/sdid/arkhangelsky.py +449 -0
- factor_factory-1.0.0/factor_factory/engines/spatial/__init__.py +64 -0
- factor_factory-1.0.0/factor_factory/engines/spatial/_base.py +59 -0
- factor_factory-1.0.0/factor_factory/engines/spatial/morans_i.py +67 -0
- factor_factory-1.0.0/factor_factory/engines/stl/__init__.py +69 -0
- factor_factory-1.0.0/factor_factory/engines/stl/_base.py +66 -0
- factor_factory-1.0.0/factor_factory/engines/stl/sktime_stl.py +71 -0
- factor_factory-1.0.0/factor_factory/engines/survival/__init__.py +105 -0
- factor_factory-1.0.0/factor_factory/engines/survival/_base.py +114 -0
- factor_factory-1.0.0/factor_factory/engines/survival/cox_ph.py +144 -0
- factor_factory-1.0.0/factor_factory/engines/survival/kaplan_meier.py +101 -0
- factor_factory-1.0.0/factor_factory/factors/__init__.py +8 -0
- factor_factory-1.0.0/factor_factory/jellycell/__init__.py +12 -0
- factor_factory-1.0.0/factor_factory/jellycell/_templates/audit.md.j2 +37 -0
- factor_factory-1.0.0/factor_factory/jellycell/_templates/diagnostics_checklist.md.j2 +52 -0
- factor_factory-1.0.0/factor_factory/jellycell/_templates/findings.md.j2 +61 -0
- factor_factory-1.0.0/factor_factory/jellycell/_templates/manuscript.md.j2 +57 -0
- factor_factory-1.0.0/factor_factory/jellycell/_templates/methodology.md.j2 +97 -0
- factor_factory-1.0.0/factor_factory/jellycell/cells.py +94 -0
- factor_factory-1.0.0/factor_factory/jellycell/figure.py +70 -0
- factor_factory-1.0.0/factor_factory/jellycell/notebooks/__init__.py +5 -0
- factor_factory-1.0.0/factor_factory/jellycell/notebooks/_scaffold.py +114 -0
- factor_factory-1.0.0/factor_factory/jellycell/notebooks/_templates/01_load.py +109 -0
- factor_factory-1.0.0/factor_factory/jellycell/notebooks/_templates/_helpers.py +19 -0
- factor_factory-1.0.0/factor_factory/jellycell/notebooks/_templates/data_README.md +37 -0
- factor_factory-1.0.0/factor_factory/jellycell/notebooks/_templates/jellycell.toml +33 -0
- factor_factory-1.0.0/factor_factory/jellycell/tearsheets/__init__.py +17 -0
- factor_factory-1.0.0/factor_factory/jellycell/tearsheets/_render.py +233 -0
- factor_factory-1.0.0/factor_factory/jellycell/tearsheets/audit.py +25 -0
- factor_factory-1.0.0/factor_factory/jellycell/tearsheets/diagnostics.py +25 -0
- factor_factory-1.0.0/factor_factory/jellycell/tearsheets/findings.py +25 -0
- factor_factory-1.0.0/factor_factory/jellycell/tearsheets/manuscript.py +29 -0
- factor_factory-1.0.0/factor_factory/jellycell/tearsheets/methodology.py +25 -0
- factor_factory-1.0.0/factor_factory/reporting/__init__.py +23 -0
- factor_factory-1.0.0/factor_factory/reporting/quarto.py +140 -0
- factor_factory-1.0.0/factor_factory/tests/__init__.py +0 -0
- factor_factory-1.0.0/factor_factory/tests/_fixtures/__init__.py +0 -0
- factor_factory-1.0.0/factor_factory/tests/_fixtures/cross_domain.py +1001 -0
- factor_factory-1.0.0/factor_factory/tests/_fixtures/synthetic_panels.py +113 -0
- factor_factory-1.0.0/factor_factory/tests/benchmarks/__init__.py +1 -0
- factor_factory-1.0.0/factor_factory/tests/benchmarks/test_panel_benchmarks.py +40 -0
- factor_factory-1.0.0/factor_factory/tests/properties/__init__.py +1 -0
- factor_factory-1.0.0/factor_factory/tests/properties/test_panel_properties.py +111 -0
- factor_factory-1.0.0/factor_factory/tests/test_batch15.py +121 -0
- factor_factory-1.0.0/factor_factory/tests/test_cross_domain.py +149 -0
- factor_factory-1.0.0/factor_factory/tests/test_diagnostics.py +136 -0
- factor_factory-1.0.0/factor_factory/tests/test_engines/__init__.py +0 -0
- factor_factory-1.0.0/factor_factory/tests/test_engines/test_batch10_imports.py +21 -0
- factor_factory-1.0.0/factor_factory/tests/test_engines/test_batch11_imports.py +82 -0
- factor_factory-1.0.0/factor_factory/tests/test_engines/test_batch12_imports.py +38 -0
- factor_factory-1.0.0/factor_factory/tests/test_engines/test_callaway_santanna.py +95 -0
- factor_factory-1.0.0/factor_factory/tests/test_engines/test_did_conformance.py +66 -0
- factor_factory-1.0.0/factor_factory/tests/test_engines/test_did_extensions.py +58 -0
- factor_factory-1.0.0/factor_factory/tests/test_engines/test_event_study.py +46 -0
- factor_factory-1.0.0/factor_factory/tests/test_engines/test_event_study_fama_french.py +84 -0
- factor_factory-1.0.0/factor_factory/tests/test_engines/test_het_te_dml.py +69 -0
- factor_factory-1.0.0/factor_factory/tests/test_engines/test_mediation.py +132 -0
- factor_factory-1.0.0/factor_factory/tests/test_engines/test_mediation_sensitivity.py +74 -0
- factor_factory-1.0.0/factor_factory/tests/test_engines/test_rdd.py +55 -0
- factor_factory-1.0.0/factor_factory/tests/test_engines/test_scm.py +33 -0
- factor_factory-1.0.0/factor_factory/tests/test_engines/test_sdid.py +94 -0
- factor_factory-1.0.0/factor_factory/tests/test_engines/test_sdid_placebo.py +39 -0
- factor_factory-1.0.0/factor_factory/tests/test_engines/test_survival.py +78 -0
- factor_factory-1.0.0/factor_factory/tests/test_engines/test_survival_strata.py +37 -0
- factor_factory-1.0.0/factor_factory/tests/test_geography.py +61 -0
- factor_factory-1.0.0/factor_factory/tests/test_jellycell_integration.py +153 -0
- factor_factory-1.0.0/factor_factory/tests/test_panel_contract.py +168 -0
- factor_factory-1.0.0/factor_factory/tests/test_polish.py +287 -0
- factor_factory-1.0.0/factor_factory/tests/test_streaming.py +77 -0
- factor_factory-1.0.0/factor_factory/tests/test_treatment_events.py +210 -0
- factor_factory-1.0.0/factor_factory/tidy/__init__.py +19 -0
- factor_factory-1.0.0/factor_factory/tidy/contracts.py +260 -0
- factor_factory-1.0.0/factor_factory/tidy/geography.py +118 -0
- factor_factory-1.0.0/factor_factory/tidy/panel.py +757 -0
- factor_factory-1.0.0/factor_factory/tidy/record_view.py +117 -0
- factor_factory-1.0.0/factor_factory/tidy/socrata.py +106 -0
- factor_factory-1.0.0/factor_factory/tidy/streaming.py +136 -0
- factor_factory-1.0.0/pyproject.toml +219 -0
- factor_factory-1.0.0/scripts/extract_release_notes.py +42 -0
- factor_factory-1.0.0/scripts/preview_tearsheet.sh +23 -0
- factor_factory-1.0.0/uv.lock +4770 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: contract-auditor
|
|
3
|
+
description: Read-only auditor for the three factor-factory contract invariants (Panel / Engine Protocol / Tearsheet JSON). Run against a git diff before merge. Flags any ceremony omissions.
|
|
4
|
+
tools: Glob, Grep, Read, Bash
|
|
5
|
+
model: sonnet
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
You audit a git diff against the three contract invariants in `docs/og_context/06_post_v0.1_roadmap.md#02-contract-invariants`. You NEVER write; you report.
|
|
9
|
+
|
|
10
|
+
## The three contracts
|
|
11
|
+
|
|
12
|
+
1. **Panel contract** (`docs/design-contracts.md`): column ordering, `period_kind` variants, treatment-column naming rules, provenance metadata shape. Source files: `factor_factory/tidy/panel.py`, `factor_factory/tidy/contracts.py`, `factor_factory/tidy/record_view.py`.
|
|
13
|
+
2. **Engine Protocol contract** (`docs/og_context/03_specs/engine_protocol.md`): the frozen `Result` dataclass shape + `Engine` Protocol shape per family. Source files: every `factor_factory/engines/<family>/_base.py`.
|
|
14
|
+
3. **Tearsheet JSON contract** (snapshot at `docs/reference/contracts.md`): `<family>_results.json` schemas that jellycell templates consume. Source files: `<Family>Result.to_dict()` implementations + `factor_factory/jellycell/_templates/*.j2` consumers.
|
|
15
|
+
|
|
16
|
+
## Procedure
|
|
17
|
+
|
|
18
|
+
1. Get the diff: `git diff main...HEAD`.
|
|
19
|
+
2. For each file touched, classify whether it intersects any of the three contracts.
|
|
20
|
+
3. If yes, verify the **ceremony** was performed:
|
|
21
|
+
- **Panel touch** → `docs/design-contracts.md` updated, `docs/reference/contracts.md` snapshot updated + `SNAPSHOT_VERSION` bumped, CHANGELOG `### Contracts` note, (if breaking) an RFC file under `docs/og_context/rfcs/` exists.
|
|
22
|
+
- **Engine Protocol touch** → same three, plus: the change is additive-only OR the version bump in `factor_factory/_version.py` is **major** (reject minor/patch for non-additive Protocol changes on ≥1.0 — pre-1.0 minor is OK).
|
|
23
|
+
- **Tearsheet JSON touch** → same three, plus: jellycell `*.j2` templates updated in lockstep OR the new key is explicitly documented as optional.
|
|
24
|
+
|
|
25
|
+
## Output shape
|
|
26
|
+
|
|
27
|
+
Produce a short report:
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
Contract audit — <N> files touched
|
|
31
|
+
|
|
32
|
+
Panel contract: OK | FAIL (<reason>)
|
|
33
|
+
Engine Protocol contract: OK | FAIL (<reason>)
|
|
34
|
+
Tearsheet JSON contract: OK | FAIL (<reason>)
|
|
35
|
+
|
|
36
|
+
Ceremonies:
|
|
37
|
+
- [ ] design-contracts.md updated (N/A if not touched)
|
|
38
|
+
- [ ] reference/contracts.md snapshot regenerated (N/A if not touched)
|
|
39
|
+
- [ ] CHANGELOG ### Contracts note (N/A if not touched)
|
|
40
|
+
- [ ] RFC filed for breaking change (N/A if additive)
|
|
41
|
+
|
|
42
|
+
Version bump is: patch | minor | major | missing
|
|
43
|
+
Recommended bump given the diff: patch | minor | major
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Cap the response at 300 words. You never modify files.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: engine-reviewer
|
|
3
|
+
description: Read-only reviewer for new engine-family PRs. Verifies each adapter conforms to the Engine Protocol contract and ships with the full set of required artifacts. Use proactively whenever a PR touches factor_factory/engines/.
|
|
4
|
+
tools: Glob, Grep, Read, Bash
|
|
5
|
+
model: sonnet
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
You are a focused reviewer for **factor-factory engine-family contributions**. You do NOT modify code — you produce a punch list of issues for the human contributor to address.
|
|
9
|
+
|
|
10
|
+
Your single source of truth is the Engine Protocol contract documented in `docs/og_context/03_specs/engine_protocol.md`. For each new adapter in `factor_factory/engines/<family>/`, verify:
|
|
11
|
+
|
|
12
|
+
## Mandatory checklist
|
|
13
|
+
|
|
14
|
+
1. **`_base.py` shape.** File exports:
|
|
15
|
+
- a frozen `@dataclass` `<Family>Result` with `to_dict()` implemented
|
|
16
|
+
- an `<Family>Engine` `Protocol` with a single `estimate(...)` method whose signature matches other families in the family
|
|
17
|
+
- a module-level `registry: EngineRegistry[<Family>Engine]` instance
|
|
18
|
+
2. **Adapter registration.** The adapter class registers itself at import time via `registry.register("<adapter-key>", <AdapterClass>())`. Import triggers only when the optional extra is installed (lazy try/except at family `__init__.py` level).
|
|
19
|
+
3. **Dispatcher.** The family exports an `estimate(panel, method=..., **kwargs)` convenience function that dispatches through `registry`. `methods=(...)` tuple form is also accepted for multi-adapter fits.
|
|
20
|
+
4. **Citation in docstring.** The adapter class docstring contains the canonical paper DOI and the reference implementation URL (usually the R package).
|
|
21
|
+
5. **Conformance test.** `factor_factory/tests/test_engines/test_<family>_<adapter>.py` exists and:
|
|
22
|
+
- instantiates a known-truth synthetic fixture
|
|
23
|
+
- fits the adapter
|
|
24
|
+
- asserts the recovered estimate is within a documented tolerance of the ground truth
|
|
25
|
+
- asserts all `Result` fields are populated (no `None`s on required fields)
|
|
26
|
+
6. **Cross-domain fixture.** `factor_factory/tests/_fixtures/cross_domain.py` has a function returning a Panel the adapter can fit, and that function is parametrized into the cross-domain conformance test.
|
|
27
|
+
7. **CHANGELOG entry.** `CHANGELOG.md` has an entry under `[Unreleased]` → `### Added` naming the family + adapter + citation.
|
|
28
|
+
8. **Supported-domains row.** `docs/supported-domains.md` has a row (or update) mentioning the new adapter.
|
|
29
|
+
9. **Cookbook page.** `docs/cookbook/<family>-<adapter>.md` exists with ≥1 worked example.
|
|
30
|
+
10. **`pyproject.toml` extras.** If a new dep was added, a `<family>` extras group exists AND the dep is folded into the `all` aggregator extras.
|
|
31
|
+
11. **Piggyback map.** If the adapter wraps an upstream package, `docs/reference/piggyback-map.md` has a row; if it's homegrown, the row marks it as an anti-piggyback with the reason.
|
|
32
|
+
12. **Contract ceremony.** If the adapter adds new keys to `<Family>Result.to_dict()`, that's an additive change to the Tearsheet JSON contract — fine, but `docs/reference/contracts.md` gets a note and the CHANGELOG has a `### Contracts` subsection.
|
|
33
|
+
13. **Lint + types.** `ruff check`, `ruff format --check`, and `mypy --strict` all pass. New `mypy.overrides` entries are added to `pyproject.toml` if the upstream package lacks stubs.
|
|
34
|
+
|
|
35
|
+
## Output shape
|
|
36
|
+
|
|
37
|
+
Produce a numbered list of failing items. If everything passes, say so explicitly. Do NOT modify files. Do NOT run the engine; you only read. Keep the response under 400 words.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Scaffold a new engine family. Arg = family name (snake_case, singular, matches dir name under factor_factory/engines/).
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Scaffold a new engine family in `factor_factory/engines/$ARGUMENTS/`. Refuse if `$ARGUMENTS` is empty, contains non-snake_case characters, or the directory already exists.
|
|
6
|
+
|
|
7
|
+
Steps:
|
|
8
|
+
|
|
9
|
+
1. **Pick a reference to copy.** Prefer `factor_factory/engines/sdid/` as the template (homegrown, with bootstrap/jackknife inference) or `factor_factory/engines/survival/` (wrapper around an upstream package). Ask the human which pattern (wrapper vs homegrown) unless `$ARGUMENTS` already has a known piggyback (check `docs/reference/piggyback-map.md`).
|
|
10
|
+
2. **Create the directory structure:**
|
|
11
|
+
- `factor_factory/engines/$ARGUMENTS/__init__.py` — exports `estimate`, `<Family>Result`, `<Family>Results`, `registry`; lazy-imports adapters inside a try/except that skips if the optional extra is missing.
|
|
12
|
+
- `factor_factory/engines/$ARGUMENTS/_base.py` — frozen `<Family>Result` dataclass with `to_dict()`, `<Family>Engine` Protocol, module-level `registry: EngineRegistry[<Family>Engine]`.
|
|
13
|
+
- `factor_factory/engines/$ARGUMENTS/<adapter>.py` — one adapter class implementing the Protocol. Stub with `raise NotImplementedError` if the math isn't done yet.
|
|
14
|
+
3. **Add a fixture.** Append a `<family>_fixture_panel()` function to `factor_factory/tests/_fixtures/cross_domain.py` that returns a Panel with a known-truth ground truth encoded in its provenance.
|
|
15
|
+
4. **Add a test.** Create `factor_factory/tests/test_engines/test_<family>_<adapter>.py` that:
|
|
16
|
+
- instantiates the fixture
|
|
17
|
+
- fits the adapter
|
|
18
|
+
- asserts the recovered estimate matches the ground truth within tolerance
|
|
19
|
+
- uses `pytest.importorskip("<upstream_package>")` at the top if the adapter wraps an external package
|
|
20
|
+
5. **Add the extras group** to `pyproject.toml` — new `[<family>]` extras entry plus fold into `all`.
|
|
21
|
+
6. **Add a piggyback-map row** to `docs/reference/piggyback-map.md`.
|
|
22
|
+
7. **Add a supported-domains row** to `docs/supported-domains.md`.
|
|
23
|
+
8. **Create a cookbook stub** at `docs/cookbook/<family>-<adapter>.md` with TODO markers.
|
|
24
|
+
9. **Add a CHANGELOG entry** under `[Unreleased]` → `### Added`.
|
|
25
|
+
10. **Print a next-steps checklist** for the human: fill in the math, write the citation docstring, verify the fixture ground truth, run `make lint test`.
|
|
26
|
+
|
|
27
|
+
Do NOT run `make lint` or `make test` yourself — the human drives that after filling in the math.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Bump factor_factory/_version.py and roll CHANGELOG [Unreleased] → new version section. Arg = patch | minor | major (default patch).
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Run these steps in order:
|
|
6
|
+
|
|
7
|
+
1. Parse `$ARGUMENTS`. Valid values: `patch` (default if omitted), `minor`, `major`.
|
|
8
|
+
2. Read current version from `factor_factory/_version.py`. Parse `__version__ = "X.Y.Z"`.
|
|
9
|
+
3. Compute new version per the policy in `docs/og_context/06_post_v0.1_roadmap.md#03-versioning-policy-minimum-bump-jellycell-inspired`:
|
|
10
|
+
- patch → `X.Y.(Z+1)`
|
|
11
|
+
- minor → `X.(Y+1).0`
|
|
12
|
+
- major → `(X+1).0.0`
|
|
13
|
+
4. Write the new version back to `factor_factory/_version.py`.
|
|
14
|
+
5. In `CHANGELOG.md`:
|
|
15
|
+
- Find the `## [Unreleased]` section.
|
|
16
|
+
- Rename it to `## [<new-version>] — <today's date in YYYY-MM-DD>`.
|
|
17
|
+
- Insert a fresh empty `## [Unreleased]` block above it with the standard subheadings: `### Added / ### Changed / ### Fixed / ### Deprecated / ### Contracts / ### Security`.
|
|
18
|
+
- Update the comparison-link footer table: `[unreleased]: https://github.com/random-walks/factor-factory/compare/v<new>...HEAD` plus `[<new>]: ...compare/v<prev>...v<new>`.
|
|
19
|
+
6. Stage both files with `git add factor_factory/_version.py CHANGELOG.md`.
|
|
20
|
+
7. Print a summary: old version, new version, number of `[Unreleased]` entries being carried over, next-step suggestion (`git commit -m "release: v<new>"` followed by `git tag v<new>`).
|
|
21
|
+
|
|
22
|
+
Do NOT commit or tag — leave that to the human.
|
|
23
|
+
|
|
24
|
+
If `$ARGUMENTS` is invalid, print the usage and exit without writing anything.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Run the contract-auditor agent against the current git diff vs main. Reports contract touches + ceremony compliance.
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Invoke the `contract-auditor` agent (via the Agent tool with `subagent_type: contract-auditor`) with this prompt:
|
|
6
|
+
|
|
7
|
+
> Audit the diff on the current branch vs `main` against the three factor-factory contract invariants (Panel / Engine Protocol / Tearsheet JSON). Use the procedure in your system prompt. Report findings.
|
|
8
|
+
|
|
9
|
+
Pass through the auditor's response verbatim. Do not add your own analysis.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Report the 18-family engine roadmap status. Counts which families are shipping, which are stub-only, which are absent.
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Read `factor_factory/engines/` and cross-reference against the 18 families listed in `docs/og_context/06_post_v0.1_roadmap.md` (did, survival, event_study, sdid, mediation + rdd, scm, het_te, dml, changepoint, stl, panel_reg, inequality, spatial, reporting_bias, hawkes, climate, diffusion).
|
|
6
|
+
|
|
7
|
+
For each family, determine status by inspecting the filesystem:
|
|
8
|
+
|
|
9
|
+
- **shipping** — `_base.py` exists, at least one adapter `.py` exists (not just `_base.py` or `__init__.py`), and there's ≥1 test file at `factor_factory/tests/test_engines/test_<family>_*.py`
|
|
10
|
+
- **scaffolded** — `_base.py` exists but no non-`_base` adapter file, or tests absent
|
|
11
|
+
- **absent** — no directory
|
|
12
|
+
|
|
13
|
+
Print a three-column markdown table: Family | Status | Adapters (comma-separated list of files found, or "—" if none). Sort by status (shipping first, then scaffolded, then absent) and then alphabetically within each bucket.
|
|
14
|
+
|
|
15
|
+
At the bottom print the summary line: `N / 18 shipping, M scaffolded, K absent.`
|
|
16
|
+
|
|
17
|
+
Do not modify files.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Preflight check before pushing a release tag. Runs lint, tests, strict docs build, hatch build, and version sanity.
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Execute these in order. Stop on first failure and report the offending step.
|
|
6
|
+
|
|
7
|
+
1. `uv run ruff format --check factor_factory docs 2>/dev/null || uv run ruff format --check factor_factory`
|
|
8
|
+
2. `uv run ruff check factor_factory`
|
|
9
|
+
3. `uv run mypy factor_factory`
|
|
10
|
+
4. `uv run pytest factor_factory/tests -q`
|
|
11
|
+
5. `uv run sphinx-build -W --keep-going -b html docs docs/_build/html` (skip if `docs/conf.py` does not yet exist — pre-Batch-1)
|
|
12
|
+
6. `uv run hatch build` (or `uv build`)
|
|
13
|
+
7. Print the version from `factor_factory/_version.py` and confirm it has no `[Unreleased]` block remaining above it in `CHANGELOG.md`.
|
|
14
|
+
8. Print the output of `git log --oneline -20` and the diff stat `git diff --stat main...HEAD` so the human can eyeball what's about to go out.
|
|
15
|
+
|
|
16
|
+
Return a final one-line verdict: `READY to tag v<version>` or `NOT READY — <reason>`.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "0.1",
|
|
3
|
+
"servers": [
|
|
4
|
+
{
|
|
5
|
+
"name": "docs-preview",
|
|
6
|
+
"command": "uv run sphinx-autobuild docs docs/_build/html --port 5190 --watch factor_factory --watch docs",
|
|
7
|
+
"port": 5190,
|
|
8
|
+
"description": "Live-reload Sphinx docs preview."
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "tearsheet-preview",
|
|
12
|
+
"command": "bash scripts/preview_tearsheet.sh",
|
|
13
|
+
"port": 5179,
|
|
14
|
+
"description": "Scaffold the demo showcase, run 01_load.py, then open the jellycell viewer."
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"name": "pytest-watch",
|
|
18
|
+
"command": "uv run pytest factor_factory/tests --lf --ff -x",
|
|
19
|
+
"description": "Re-run pytest focused on last-failed, first-failed, fail-fast."
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: engine-protocol
|
|
3
|
+
description: Pre-edit ceremony checklist when touching any factor_factory/engines/*/_base.py or the Engine Protocol contract. Triggers on reads/edits of _base.py, _registry.py, or Result dataclasses.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Engine Protocol ceremony
|
|
7
|
+
|
|
8
|
+
**You are about to touch the Engine Protocol contract** — one of the three factor-factory §0.2 invariants. Before you write, confirm you know which change type this is:
|
|
9
|
+
|
|
10
|
+
| Change type | Example | Bump | Ceremony |
|
|
11
|
+
|---|---|---|---|
|
|
12
|
+
| Additive (new optional field on `Result`) | Adding `jackknife_replicates: int \| None = None` | patch / minor | CHANGELOG `### Added` entry, snapshot regen |
|
|
13
|
+
| New adapter in existing family | `engines.did.sun_abraham` | minor | Standard engine-scaffold flow |
|
|
14
|
+
| New family | `engines.rdd` | minor | Use `/add-engine` |
|
|
15
|
+
| Renaming a `Result` field | `estimate` → `att` | **BREAKING** | RFC + **major** bump |
|
|
16
|
+
| Removing a `Result` field | Any removal | **BREAKING** | RFC + **major** bump |
|
|
17
|
+
| Changing the `Engine` Protocol signature | Adding a required kwarg to `estimate()` | **BREAKING** | RFC + **major** bump |
|
|
18
|
+
|
|
19
|
+
## The files you're about to touch
|
|
20
|
+
|
|
21
|
+
- `_base.py` — Protocol + frozen Result. **Frozen means frozen**: do not add `@dataclass.__post_init__` logic that mutates fields. Do not widen `Result` into a non-frozen class.
|
|
22
|
+
- `_registry.py` or the shared `engines/_registry.py` — `EngineRegistry` generic. Changing the registry shape affects every family simultaneously; prefer family-local workarounds.
|
|
23
|
+
- `<adapter>.py` files — adapters are free to refactor internally, but they must continue to satisfy the Protocol.
|
|
24
|
+
|
|
25
|
+
## Ceremony steps
|
|
26
|
+
|
|
27
|
+
1. If additive, proceed. CHANGELOG entry + snapshot regen + cookbook update if user-facing.
|
|
28
|
+
2. If breaking, **stop**. Write an RFC in `docs/og_context/rfcs/<slug>.md` (use `docs/og_context/05_rfc_template.md`). Get human sign-off.
|
|
29
|
+
3. Update `docs/reference/contracts.md` snapshot section with the new shape. Bump `SNAPSHOT_VERSION`.
|
|
30
|
+
4. Update `docs/og_context/03_specs/engine_protocol.md` if the prose is now stale.
|
|
31
|
+
5. Make sure `<Family>Result.to_dict()` still round-trips through the tearsheet templates under `factor_factory/jellycell/_templates/`.
|
|
32
|
+
|
|
33
|
+
## Golden rule
|
|
34
|
+
|
|
35
|
+
If downstream adopters (nyc311, subway-access) would have to change a line of code to upgrade past this PR, it's breaking. Major bump or don't ship.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: fixture-parity
|
|
3
|
+
description: Every new engine adapter MUST ship with a truth-tracking synthetic fixture in cross_domain.py AND a parametrized conformance test. Triggers when adding a file under factor_factory/engines/.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Fixture parity
|
|
7
|
+
|
|
8
|
+
Every adapter that lands in `factor_factory/engines/` must have a matching synthetic fixture and a conformance test that proves the adapter recovers the ground truth.
|
|
9
|
+
|
|
10
|
+
## The fixture
|
|
11
|
+
|
|
12
|
+
Add to `factor_factory/tests/_fixtures/cross_domain.py`:
|
|
13
|
+
|
|
14
|
+
```python
|
|
15
|
+
def <family>_<scenario>_panel() -> Panel:
|
|
16
|
+
"""
|
|
17
|
+
Synthetic Panel with known ground truth embedded in the provenance.
|
|
18
|
+
|
|
19
|
+
Ground truth: ATT = 4.0 (units: outcome-level), n_units_treated = 5,
|
|
20
|
+
treatment_date = 2024-06-01, controls = random walk, treated = random
|
|
21
|
+
walk + 4 * 1[t ≥ treatment_date]. Recoverable by any DiD estimator
|
|
22
|
+
within 1 SE at n=100 units.
|
|
23
|
+
"""
|
|
24
|
+
rng = np.random.default_rng(SEED)
|
|
25
|
+
# ... build records ...
|
|
26
|
+
panel = Panel.from_records(records, ...)
|
|
27
|
+
# Stash the truth in provenance.annotations so tests can assert against it:
|
|
28
|
+
panel.provenance.annotations["ground_truth_att"] = 4.0
|
|
29
|
+
return panel
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## The test
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
# factor_factory/tests/test_engines/test_<family>_<adapter>.py
|
|
36
|
+
import pytest
|
|
37
|
+
from factor_factory.tests._fixtures.cross_domain import <family>_<scenario>_panel
|
|
38
|
+
|
|
39
|
+
pytestmark = pytest.mark.importorskip("<upstream_package_or_skip>")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test_<adapter>_recovers_ground_truth():
|
|
43
|
+
panel = <family>_<scenario>_panel()
|
|
44
|
+
result = estimate(panel, method="<adapter-key>")
|
|
45
|
+
truth = panel.provenance.annotations["ground_truth_att"]
|
|
46
|
+
assert abs(result.estimate - truth) < max(2 * result.std_error, 0.1 * truth), (
|
|
47
|
+
f"Recovered {result.estimate} ± {result.std_error} vs ground truth {truth}"
|
|
48
|
+
)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Parametrize the cross-domain conformance test
|
|
52
|
+
|
|
53
|
+
In `factor_factory/tests/test_cross_domain.py`, register the new fixture so it runs through the universal Panel-contract conformance loop. Every fixture must:
|
|
54
|
+
|
|
55
|
+
- pass `Panel.validate()`
|
|
56
|
+
- round-trip through parquet via `panel.to_parquet()` + `Panel.from_parquet()`
|
|
57
|
+
- produce a sane `Panel.summary()` dict
|
|
58
|
+
- expose `provenance.annotations["ground_truth_<metric>"]` for the metric the family produces
|
|
59
|
+
|
|
60
|
+
## Why this matters
|
|
61
|
+
|
|
62
|
+
Without a truth-tracking fixture, an engine adapter is just claiming to implement a method — not proving it. SDID + Mediation validated against ground truth to within 1 SE before merge; every subsequent family must meet or exceed that bar.
|
|
63
|
+
|
|
64
|
+
## Tolerance guidance
|
|
65
|
+
|
|
66
|
+
- For unbiased estimators: `abs(recovered - truth) < 2 * se`
|
|
67
|
+
- For estimators with known finite-sample bias: document the bias in the adapter docstring and use `abs(recovered - expected_biased) < 2 * se`
|
|
68
|
+
- For methods that return a distribution (bootstrap CIs): assert the 95% CI contains the truth
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: piggyback-first
|
|
3
|
+
description: Before writing engine math from scratch, consult docs/reference/piggyback-map.md to confirm no canonical upstream package exists to wrap. Triggers when adding a new adapter or implementing a statistical method.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Piggyback-first
|
|
7
|
+
|
|
8
|
+
Factor-factory is an **adapter-first** framework. Before you write any math:
|
|
9
|
+
|
|
10
|
+
1. Open `docs/reference/piggyback-map.md`. Search for the method name (e.g. "Callaway-Sant'Anna", "causal forest", "Mann-Kendall").
|
|
11
|
+
2. **If there's a row for it**, you wrap the package listed. Do not reimplement.
|
|
12
|
+
3. **If there's no row**, check whether a well-maintained Python or R package exists:
|
|
13
|
+
- PyPI: `pip index versions <guess>` or `https://pypi.org/project/<guess>/`
|
|
14
|
+
- R: CRAN task views + the canonical paper's code supplement
|
|
15
|
+
- If you find one, add a row to the piggyback map and wrap it.
|
|
16
|
+
4. **Only port from scratch** (anti-piggyback) when:
|
|
17
|
+
- No maintained Python equivalent exists AND
|
|
18
|
+
- The R package is too tangled to wrap cleanly AND
|
|
19
|
+
- The method is small enough (~100–300 LOC) to port correctly
|
|
20
|
+
|
|
21
|
+
## Current anti-piggybacks (existing homegrown ports)
|
|
22
|
+
|
|
23
|
+
- `engines.sdid.SyntheticDidEngine` — Arkhangelsky 2021. Reference: R `synthdid`. Partial Python ports (`pysdid`) were stale.
|
|
24
|
+
- `engines.mediation.FourWayMediationEngine` — VanderWeele 2014. Reference: R `CMAverse`. `statsmodels.stats.mediation` only supports the 2-component decomposition; PyPI `mediation` is stale.
|
|
25
|
+
- `engines.event_study.market_adjusted` — trivial math; dep-free by design.
|
|
26
|
+
- (Planned) `engines.reporting_bias.latent_em` — no mature Python package for two-class latent-EM under-reporting estimation.
|
|
27
|
+
|
|
28
|
+
## What "wrap, don't reimplement" means
|
|
29
|
+
|
|
30
|
+
The adapter must:
|
|
31
|
+
- Import the upstream package (guarded by a lazy try/except at the family `__init__.py` level so the extras gate works)
|
|
32
|
+
- Translate the Panel + kwargs into whatever shape the upstream expects
|
|
33
|
+
- Translate the upstream's result back into the frozen `<Family>Result` dataclass
|
|
34
|
+
- Preserve the upstream's numeric output verbatim — no homegrown bias corrections or tweaks without a citation
|
|
35
|
+
|
|
36
|
+
If you catch yourself writing matrix math in an adapter that wraps a package, you're probably doing it wrong. Pause and confirm the upstream doesn't already have that API.
|
|
37
|
+
|
|
38
|
+
## Update the map
|
|
39
|
+
|
|
40
|
+
Any new adapter → add a row:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
| Method | Piggyback: `<pkg>` | <anti-piggyback reason if applicable> |
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
CHANGELOG `### Added` entry notes the piggyback in parens.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: release-bump
|
|
3
|
+
description: One-screen rubric for deciding patch vs minor vs major. Triggers when closing a PR or about to run /bump.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Release bump rubric
|
|
7
|
+
|
|
8
|
+
Factor-factory follows jellycell's **minimum-bump** policy: patch bumps are cheap, hoard nothing. Cut releases frequently.
|
|
9
|
+
|
|
10
|
+
## Decision tree
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
Did the diff touch any contract invariant (Panel / Engine Protocol / Tearsheet JSON)?
|
|
14
|
+
├── Yes, but purely additive (new optional field, new adapter, new family) → minor
|
|
15
|
+
├── Yes, and breaking (renamed field, removed field, changed required signature) → major (post-1.0) OR minor (pre-1.0)
|
|
16
|
+
└── No contract touch → continue
|
|
17
|
+
|
|
18
|
+
Is the change user-visible (new public API, new cookbook-worthy behavior, new adapter)?
|
|
19
|
+
├── Yes → minor
|
|
20
|
+
└── No → continue
|
|
21
|
+
|
|
22
|
+
Is the change a bug fix, docs tidy, internal refactor, dep bump that isn't breaking, new fixture, new test?
|
|
23
|
+
└── Yes → patch
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Rules of thumb
|
|
27
|
+
|
|
28
|
+
- **When in doubt, patch.** You can always cut another release tomorrow.
|
|
29
|
+
- **"If the change is worth merging, it's worth a bump"** — even doc-only cleanups land under a patch bump once a week, not once a quarter.
|
|
30
|
+
- **Major bumps are expensive.** They force downstream adopters to read the CHANGELOG. Earn them.
|
|
31
|
+
- **Pre-1.0:** breaking changes are minor per SemVer convention; no majors until the first stable release cuts.
|
|
32
|
+
- **Post-1.0:** breaking contract changes are **always** major. No exceptions.
|
|
33
|
+
|
|
34
|
+
## Batch cadence during the v0.2 → v1.12 roadmap
|
|
35
|
+
|
|
36
|
+
Each batch in `docs/og_context/06_post_v0.1_roadmap.md` ends with a minor bump (new engine family or substantial framework addition). Intra-batch follow-up PRs use patch bumps.
|
|
37
|
+
|
|
38
|
+
## What goes into the CHANGELOG entry
|
|
39
|
+
|
|
40
|
+
Short. Specific. Link citations.
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
## [1.4.0] — 2026-05-15
|
|
44
|
+
|
|
45
|
+
### Added
|
|
46
|
+
- `engines.rdd.rd_robust` — Regression Discontinuity via `rdrobust`
|
|
47
|
+
(Calonico-Cattaneo-Titiunik 2014, https://doi.org/10.3982/ECTA11757).
|
|
48
|
+
Supports sharp + fuzzy RDD, MSE-optimal bandwidth, robust bias-corrected SEs.
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Not:
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
- Added RDD stuff (#47)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Final step
|
|
58
|
+
|
|
59
|
+
After running `/bump`, review the generated CHANGELOG section. Rewrite any thin "stuff" entries into specific claims with citations. Then `git commit`.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: tearsheet-json-contract
|
|
3
|
+
description: Reminder that `*_results.json` shapes produced by Result.to_dict() are a public contract consumed by jellycell tearsheet templates and downstream adopters. Triggers when editing to_dict() methods or tearsheet *.j2 templates.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Tearsheet JSON contract
|
|
7
|
+
|
|
8
|
+
The JSON files produced by each engine family's `Result.to_dict()` method are read by:
|
|
9
|
+
|
|
10
|
+
1. The jellycell tearsheet Jinja templates under `factor_factory/jellycell/_templates/*.j2`.
|
|
11
|
+
2. Any downstream showcase that archives results to disk and re-reads them later.
|
|
12
|
+
3. Human reviewers doing eyeball checks via `jq` / `cat`.
|
|
13
|
+
|
|
14
|
+
This makes the JSON shape a contract. The ceremony for changes:
|
|
15
|
+
|
|
16
|
+
## Additive changes (safe)
|
|
17
|
+
|
|
18
|
+
- **Adding a new optional key** to `to_dict()` → safe. Patch or minor bump. CHANGELOG `### Added` note.
|
|
19
|
+
- **Adding a new engine family** → safe; introduces a new `<family>_results.json` shape. Document the shape in `docs/reference/contracts.md` and add a per-family block in the tearsheet template.
|
|
20
|
+
|
|
21
|
+
## Breaking changes (costly)
|
|
22
|
+
|
|
23
|
+
- **Renaming a key** → breaking. Major bump on ≥1.0. Must land with:
|
|
24
|
+
- RFC under `docs/og_context/rfcs/`
|
|
25
|
+
- Migration note in `docs/migration/`
|
|
26
|
+
- Template update in lockstep (both old + new key support during a deprecation window)
|
|
27
|
+
- **Removing a key** → breaking. Same ceremony.
|
|
28
|
+
- **Changing the type of a value** (e.g. `float → dict`) → breaking. Same ceremony.
|
|
29
|
+
|
|
30
|
+
## Snapshot gate
|
|
31
|
+
|
|
32
|
+
`docs/reference/contracts.md` holds a pinned JSON-schema snapshot per family. Any touch to a `to_dict()` method that changes the schema must regenerate the snapshot and bump `SNAPSHOT_VERSION` for that family. The contract-auditor agent checks this.
|
|
33
|
+
|
|
34
|
+
## Template-side view
|
|
35
|
+
|
|
36
|
+
The `.j2` templates under `factor_factory/jellycell/_templates/` are how the tearsheet actually reads the JSON. When you add a key to `to_dict()`, the template that consumes it also gets a patch — otherwise the new key is invisible. When you rename or remove a key, the template must be updated in lockstep OR tolerate both forms.
|
|
37
|
+
|
|
38
|
+
## Example safe additive change
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
# engines/did/_base.py
|
|
42
|
+
@dataclass(frozen=True)
|
|
43
|
+
class DidResult:
|
|
44
|
+
estimate: float
|
|
45
|
+
std_error: float
|
|
46
|
+
method: str
|
|
47
|
+
# NEW in v1.1.0:
|
|
48
|
+
effective_sample_size: int | None = None # additive, optional, default None
|
|
49
|
+
|
|
50
|
+
def to_dict(self) -> dict[str, Any]:
|
|
51
|
+
return {
|
|
52
|
+
"estimate": self.estimate,
|
|
53
|
+
"std_error": self.std_error,
|
|
54
|
+
"method": self.method,
|
|
55
|
+
"effective_sample_size": self.effective_sample_size, # NEW
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Template:
|
|
60
|
+
|
|
61
|
+
```jinja
|
|
62
|
+
{% if r.effective_sample_size is not none %}
|
|
63
|
+
<p>Effective sample size: {{ r.effective_sample_size }}</p>
|
|
64
|
+
{% endif %}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Safe, additive, tearsheet renders fine for both old and new JSON.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<!-- factor-factory PR template — short, non-bureaucratic. Delete sections that don't apply. -->
|
|
2
|
+
|
|
3
|
+
## Summary
|
|
4
|
+
|
|
5
|
+
<!-- 1–3 bullets. What does this PR do and why? -->
|
|
6
|
+
|
|
7
|
+
## Batch ref (if applicable)
|
|
8
|
+
|
|
9
|
+
<!-- docs/og_context/06_post_v0.1_roadmap.md#batch-N -->
|
|
10
|
+
|
|
11
|
+
## Contract touches
|
|
12
|
+
|
|
13
|
+
<!-- Tick any that apply. If any are ticked, confirm the ceremony was performed per docs/og_context/06_post_v0.1_roadmap.md#02. -->
|
|
14
|
+
|
|
15
|
+
- [ ] Panel contract (`factor_factory/tidy/panel.py`, `contracts.py`, `record_view.py`)
|
|
16
|
+
- [ ] Engine Protocol contract (`engines/<family>/_base.py`)
|
|
17
|
+
- [ ] Tearsheet JSON contract (`Result.to_dict()` changes or `_templates/*.j2` changes)
|
|
18
|
+
- [ ] None of the above
|
|
19
|
+
|
|
20
|
+
If any ticked:
|
|
21
|
+
|
|
22
|
+
- [ ] `docs/reference/contracts.md` snapshot regenerated + `SNAPSHOT_VERSION` bumped
|
|
23
|
+
- [ ] CHANGELOG `### Contracts` note
|
|
24
|
+
- [ ] RFC filed (for breaking changes only) — link: _______________
|
|
25
|
+
|
|
26
|
+
## Checklist
|
|
27
|
+
|
|
28
|
+
- [ ] `make lint && make test && make docs-build` green locally
|
|
29
|
+
- [ ] `/contract-check` clean
|
|
30
|
+
- [ ] CHANGELOG `[Unreleased]` entry under the right header (Added / Changed / Fixed / Deprecated / Contracts / Security)
|
|
31
|
+
- [ ] New optional-dependency extra? → folded into `all` extras
|
|
32
|
+
- [ ] New engine family? → `/engine-status` shows it as shipping; piggyback-map row added; supported-domains row added; cookbook stub exists
|
|
33
|
+
- [ ] Citations (DOI + reference R package URL) present in adapter docstring
|
|
34
|
+
|
|
35
|
+
## Citations (for new engine adapters)
|
|
36
|
+
|
|
37
|
+
<!-- Paper + reference implementation URL -->
|
|
38
|
+
|
|
39
|
+
## Test plan
|
|
40
|
+
|
|
41
|
+
<!-- What did you run to convince yourself this works? -->
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
concurrency:
|
|
9
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
10
|
+
cancel-in-progress: true
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
test:
|
|
14
|
+
name: pytest (${{ matrix.os }} / py${{ matrix.python-version }})
|
|
15
|
+
runs-on: ${{ matrix.os }}
|
|
16
|
+
strategy:
|
|
17
|
+
fail-fast: false
|
|
18
|
+
matrix:
|
|
19
|
+
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
20
|
+
python-version: ["3.12", "3.13"]
|
|
21
|
+
steps:
|
|
22
|
+
- uses: actions/checkout@v4
|
|
23
|
+
- name: Install uv
|
|
24
|
+
uses: astral-sh/setup-uv@v3
|
|
25
|
+
with:
|
|
26
|
+
enable-cache: true
|
|
27
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
28
|
+
run: uv python install ${{ matrix.python-version }}
|
|
29
|
+
- name: Create venv
|
|
30
|
+
run: uv venv --python ${{ matrix.python-version }} .venv
|
|
31
|
+
- name: Install dependencies (default + did + survival + event-study + dev)
|
|
32
|
+
run: uv pip install -e ".[did,survival,event-study,dev]"
|
|
33
|
+
- name: Run pytest
|
|
34
|
+
run: uv run --no-project pytest -v
|
|
35
|
+
|
|
36
|
+
lint:
|
|
37
|
+
name: ruff
|
|
38
|
+
runs-on: ubuntu-latest
|
|
39
|
+
steps:
|
|
40
|
+
- uses: actions/checkout@v4
|
|
41
|
+
- name: Install uv
|
|
42
|
+
uses: astral-sh/setup-uv@v3
|
|
43
|
+
with:
|
|
44
|
+
enable-cache: true
|
|
45
|
+
- name: Set up Python
|
|
46
|
+
run: uv python install 3.12
|
|
47
|
+
- name: Create venv
|
|
48
|
+
run: uv venv --python 3.12 .venv
|
|
49
|
+
- name: Install dev tooling
|
|
50
|
+
run: uv pip install -e ".[dev]"
|
|
51
|
+
- name: ruff format --check
|
|
52
|
+
run: uv run --no-project ruff format --check factor_factory
|
|
53
|
+
- name: ruff lint
|
|
54
|
+
run: uv run --no-project ruff check factor_factory
|
|
55
|
+
|
|
56
|
+
typecheck:
|
|
57
|
+
name: mypy
|
|
58
|
+
runs-on: ubuntu-latest
|
|
59
|
+
steps:
|
|
60
|
+
- uses: actions/checkout@v4
|
|
61
|
+
- name: Install uv
|
|
62
|
+
uses: astral-sh/setup-uv@v3
|
|
63
|
+
with:
|
|
64
|
+
enable-cache: true
|
|
65
|
+
- name: Set up Python
|
|
66
|
+
run: uv python install 3.12
|
|
67
|
+
- name: Create venv
|
|
68
|
+
run: uv venv --python 3.12 .venv
|
|
69
|
+
- name: Install dependencies
|
|
70
|
+
run: uv pip install -e ".[did,survival,event-study,dev]"
|
|
71
|
+
- name: mypy
|
|
72
|
+
run: uv run --no-project mypy factor_factory
|
|
73
|
+
|
|
74
|
+
docs:
|
|
75
|
+
name: sphinx docs
|
|
76
|
+
runs-on: ubuntu-latest
|
|
77
|
+
steps:
|
|
78
|
+
- uses: actions/checkout@v4
|
|
79
|
+
- name: Install uv
|
|
80
|
+
uses: astral-sh/setup-uv@v3
|
|
81
|
+
with:
|
|
82
|
+
enable-cache: true
|
|
83
|
+
- name: Set up Python
|
|
84
|
+
run: uv python install 3.12
|
|
85
|
+
- name: Create venv
|
|
86
|
+
run: uv venv --python 3.12 .venv
|
|
87
|
+
- name: Install docs + runtime dependencies
|
|
88
|
+
run: uv pip install -e ".[docs,did,survival,event-study]"
|
|
89
|
+
- name: sphinx-build -W --keep-going
|
|
90
|
+
run: uv run --no-project sphinx-build -W --keep-going -b html docs docs/_build/html
|
|
91
|
+
- name: Upload HTML artifact
|
|
92
|
+
uses: actions/upload-artifact@v4
|
|
93
|
+
with:
|
|
94
|
+
name: docs-html
|
|
95
|
+
path: docs/_build/html
|
|
96
|
+
retention-days: 7
|