> ## 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.

# etl/build_events.py

> Build the `events` table (see docs/data-contracts.md) from config/event_types.csv and config/event_dates.csv, and write a copy to data/events.parquet for browsing.

`etl/build_events.py` · chapter [Building a row](https://calendar-effects.mintlify.site/tour/03-building-a-row.md), file 6 · 35 lines · [open in the repository](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/etl/build_events.py)

## What it does

Build the `events` table (see docs/data-contracts.md) from config/event\_types.csv
and config/event\_dates.csv, and write a copy to data/events.parquet for browsing.

Pipeline code does not read this file: it calls common.contracts.expand\_events
directly, so it always matches config/.

Run: python3 etl/build\_events.py

## What is inside

* **`OUTPUT_PATH`** · [line 17](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/etl/build_events.py#L17)
* **`main()`** · [line 20](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/etl/build_events.py#L20)

## Connections

**Uses:** [`src/common/contracts.py`](https://calendar-effects.mintlify.site/reference/src/common/contracts), [`src/common/settings.py`](https://calendar-effects.mintlify.site/reference/src/common/settings), [`src/common/study.py`](https://calendar-effects.mintlify.site/reference/src/common/study)

## Source

```python title="etl/build_events.py" lines expandable theme={null}
"""Build the `events` table (see docs/data-contracts.md) from config/event_types.csv
and config/event_dates.csv, and write a copy to data/events.parquet for browsing.

Pipeline code does not read this file: it calls common.contracts.expand_events
directly, so it always matches config/.

Run: python3 etl/build_events.py
"""
from __future__ import annotations

import pandas as pd

from common.contracts import expand_events, pandas_columns, require_contract
from common.settings import DATA_DIR, REPO_ROOT
from common.study import STUDY_END_YEAR, STUDY_START_YEAR

OUTPUT_PATH = DATA_DIR / "events.parquet"


def main() -> None:
    rows = expand_events(STUDY_START_YEAR, STUDY_END_YEAR)
    df = pd.DataFrame(rows)
    require_contract("events", pandas_columns(df))

    OUTPUT_PATH.parent.mkdir(parents=True, exist_ok=True)
    df.to_parquet(OUTPUT_PATH, index=False)

    print(f"{len(df)} event occurrences, {df['event_type'].nunique()} event types, "
          f"{STUDY_START_YEAR}-{STUDY_END_YEAR}")
    print(df.groupby("event_type").size())
    print(f"written to {OUTPUT_PATH.relative_to(REPO_ROOT)}")


if __name__ == "__main__":
    main()
```


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