> ## Documentation Index
> Fetch the complete documentation index at: https://calendar-effects.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 0005. Everything that defines the study is read from config/ and common/

* **Date:** 2026-11-16
* **Status:** Agreed 2026-11-25 (proposed by Mahad; merged to `main` so everyone's AI assistant sees it)
* **Agreed by:** Sanchi (2026-11-18), Mahad (2026-11-25)

## Context

Decision 0003 made events data instead of code, but nothing else was:

* The tickers were a list in `etl/prices_download.py`. The ETL guide's `lookup/tickers.csv` was never made, so the retailer labels lived nowhere.
* The years 2016–2025 were typed into 7 files, the FRED series into `etl/retail_clean.py`, and the Kafka topic and servers into 4 scripts.
* Every script used paths relative to the folder it was run from, and `join_master.py` needed a `sys.path` change to import `common`.
* The contracts still described the original plan (hourly `prices` with `timestamp_utc`, an `attention` table), not the files the ETL built. `pageviews` and `retail_sales` had no contract, and `volume` was int32 where the contract said long.

Adding a retailer or changing the period meant hunting through scripts, and nothing would have caught a missed copy.

## Decision

* **What is studied lives in `config/`,** one CSV per list, each a contract with a loader in `common.contracts` that checks the header:
  * `event_types.csv` and `event_dates.csv` (as in 0003)
  * `retailers.csv` (new; replaces the ticker list and the planned `tickers.csv`; has `in_scope`, like events)
  * `wiki_articles.csv` (moved from `lookup/wiki_to_ticker.csv`, plus a `notes` column)
  * `retail_series.csv` (new; replaces the dict in `retail_clean.py`)
* **How it is studied stays in `common.study`.** It gains `STUDY_START` and `STUDY_END`. The market index is not a retailer; `price_tickers()` adds it to the downloads.
* **Where things are goes in `common.settings`:** the `config/`, `raw/`, `clean/`, `data/` and `checkpoints/` paths, `clean_path(dataset)`, the run folders (`REPLAY_DIR`, `STREAM_DIR`, `RESULTS_DIR`), and `KAFKA_BOOTSTRAP`, which the environment variable of the same name overrides.
* **The contracts describe the files as built:** `prices` (daily, `volume` long), `pageviews`, `retail_sales`, `retailers`, `wiki_articles`, `retail_series`. `attention` and the unused `prices`/`attention` Kafka topics are removed.
* **Every ETL script validates its output** with `require_contract(dataset, pandas_columns(df))` before writing.
* **`src/` is an installable package** (`pyproject.toml`; `requirements.txt` installs it with `-e .`), so scripts run from any folder without `sys.path` changes. `src/ingest/build_events.py` moved to `etl/build_events.py`; `src/ingest/` and `lookup/` are gone.
* **Enforced by tests.** A hook that Claude Code and Cursor both run tests a copy of what each commit will contain, so each commit has to work on its own (`tests/test_commit_hook.py` tests the hook itself).
  * `tests/test_no_hardcoding.py`: no ticker, event, title, series, year, path, topic or server in the code of `etl/`, `src/` or `scripts/`, whether as a literal or as a word inside a string. A line ending `# not-config: <reason>` is the visible exception for values that only look like config.
  * `tests/test_config.py`: every registry row is valid and consistent.
  * `tests/test_clean_files.py`: the committed clean files match their contracts and `config/`, cover the whole study period, and carry exactly the calendar's events. When they don't, the failure names the script to re-run.

## Alternatives considered

* **One Python settings module with lists of tickers and series:** simpler, but lists in code invite copies, and a CSV is easier for teammates to edit and review.
* **Labels only in `config/retailers.csv`, not in `master`:** the first version of this decision. Meanwhile Anushiya built `lookup/tickers.csv` and put the labels into `master`, as the ETL guide planned (commit 14531b0). The merge (2026-11-17) keeps both ideas. `master` carries `country` and `retailer_type`, so analyses can split online vs store directly, and `etl/join_master.py` copies them from `config/retailers.csv`, so they are typed once. `lookup/tickers.csv`, `etl/tickers_build.py` and `clean/tickers.parquet` were removed as copies.
* **Moving `etl/` into `src/ingest/` and `clean/` into `data/clean/`,** as the first layout proposed: more change for everyone and no benefit. The docs now describe the layout the team actually uses.
* **Wrapping each ETL script in functions:** skipped. The flat scripts are short, each has one owner, and they read top to bottom for teammates who are learning.

## Consequences

* **Everyone:** run `pip install -r requirements.txt` once more (it installs `src/` as a package; without it `import common` fails). Run `python3 -m pytest -q` before committing; Claude Code and Cursor do it automatically, and refuse `git add` and `git commit` in one command. To add a retailer, an article or a series, see "How to add or change things" in AGENTS.md.
* **The rewritten scripts give the same data.** The old and new versions were run on the same raw files and produced identical values. The only change is that `prices` and `master` now store `volume` as long, so both files were regenerated.
* **Mahad:** `etl/prices_download.py`, `etl/prices_clean.py`, the producers, the streaming job and `scripts/check_streaming.py` changed.
* **Sanchi, please review:** `etl/pageviews_download.py`, `etl/pageviews_clean.py`, `etl/join_master.py`, `src/producers/replay_master.py`, `scripts/create_topics.py`, `scripts/peek_topic.py`, and `config/wiki_articles.csv` (moved from `lookup/`). `join_master.py` no longer waits for `clean/tickers.parquet`, and `pageviews_clean.py` cuts the raw views to the study period before picking each ticker's current title.
* **Anushiya, please review:** `config/retailers.csv` (the ticker list, with three candidates marked `in_scope = no`) and `etl/build_events.py` (moved from `src/ingest/`; it now writes to `data/events.parquet`). Also the merge with your tickers work: `master` keeps your `country` and `retailer_type` columns, now read from `config/retailers.csv` (Shopify's country is `CA` there, `Canada` in your list), so `lookup/tickers.csv`, `etl/tickers_build.py` and `clean/tickers.parquet` are gone and `run_everything.sh` no longer calls the build script.
* **Areej, please review:** `etl/retail_clean.py` (now casts `sales` back to whole numbers after dropping FRED's missing values) and `config/retail_series.csv`. The batch study should take its tickers, events, windows and paths from the same places, and write under `RESULTS_DIR` (`.claude/rules/event-study.md`). `src/eventstudy/` now has an `__init__.py`.
* **Open:** TSX candidates (`L.TO`, `CTC-A.TO`) would need a TSX market index, so `MARKET_TICKER` would become per country. Decide that before putting them in scope.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.