Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,30 @@ jobs:
python-version:
- '3.14'
steps:
- uses: actions/checkout@v6
- uses: prefix-dev/setup-pixi@v0.9.5
- uses: actions/checkout@v7.0.1
- uses: prefix-dev/setup-pixi@v0.10.2
with:
pixi-version: v0.69.0
pixi-version: v0.81.0
cache: true
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
frozen: true
environments: py314
- name: Run pytest
shell: bash {0}
run: pixi run -e py314 tests-with-cov
run: pixi run --locked -e py314 tests-with-cov
- name: Upload coverage report
if: runner.os == 'Linux' && matrix.python-version == '3.14'
uses: codecov/codecov-action@v5
uses: codecov/codecov-action@v7.1.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
run-ty:
name: Run ty
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: prefix-dev/setup-pixi@v0.9.5
- uses: actions/checkout@v7.0.1
- uses: prefix-dev/setup-pixi@v0.10.2
with:
pixi-version: v0.69.0
pixi-version: v0.81.0
cache: true
cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
frozen: true
Expand Down
10 changes: 3 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ docs/variables.md
*.spec
.eggs/
.installed.cfg
bld/
build/
dist/
MANIFEST
Expand Down Expand Up @@ -81,8 +80,10 @@ __pycache__/
# pytask
.pytask/
.pytask.sqlite3
pytask.lock
bld/
out/
pytask.lock
pytask.lock.journal

# Ruff
.ruff_cache/
Expand All @@ -98,8 +99,3 @@ htmlcov/

# Version file (generated by hatch-vcs)
src/*/_version.py

# External Pro-review artifacts (local only)
pro-audit-bundle.zip
pro-audit-bundle/
report.md
88 changes: 73 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repos:
- id: check-useless-excludes
# - id: identity # Prints all files passed to pre-commits. Debugging.
- repo: https://github.com/tox-dev/pyproject-fmt
rev: v2.25.1
rev: v2.29.4
hooks:
- id: pyproject-fmt
- repo: https://github.com/lyz-code/yamlfix
Expand Down Expand Up @@ -49,11 +49,11 @@ repos:
- id: yamllint
exclude: variable_to_metadata_mapping\.yaml
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.37.4
rev: 0.38.0
hooks:
- id: check-github-workflows
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.20
rev: v0.16.8
hooks:
- id: ruff-check
types_or:
Expand All @@ -68,14 +68,14 @@ repos:
- pyi
- python
- repo: https://github.com/astral-sh/ty-pre-commit
rev: v0.0.56
rev: v0.0.83
hooks:
- id: ty
# `--no-project` keeps uv from creating a `.venv`/`uv.lock` in this
# pixi-managed repo; ty resolves third-party imports from the env named
# in `[tool.ty] environment.python` (run `pixi install` once).
args:
- --no-project
# Run ty directly so import resolution uses `[tool.ty] environment.python`.
# Keep this dependency pin aligned with the hook revision above.
entry: ty check
additional_dependencies:
- ty==0.0.83
- repo: https://github.com/executablebooks/mdformat
rev: 1.0.0
hooks:
Expand All @@ -87,17 +87,75 @@ repos:
args:
- --wrap
- '88'
files: (AGENTS\.md|CLAUDE\.md|README\.md|modules/.*\.md|profiles/.*\.md)
files: (AGENTS\.md|README\.md|modules/.*\.md|profiles/.*\.md)
- id: mdformat
additional_dependencies:
- mdformat-myst
- mdformat-ruff
args:
- --wrap
- '88'
files: docs/.
- repo: https://github.com/codespell-project/codespell
rev: v2.4.2
rev: v2.4.3
hooks:
- id: codespell
args:
- --skip="**.ipynb"
- --ignore-words=.codespell-wordlist.txt
additional_dependencies:
- tomli
- repo: local
hooks:
# Runs at pre-commit stage and fails if the config declares pre-push hooks
# that this clone never installed — otherwise they look active and silently
# never fire.
- id: pre-push-hooks-installed
name: pre-push hooks are installed in this clone
entry: .ai-instructions/hooks/check_pre_push_installed.py
language: script
pass_filenames: false
always_run: true
# `--check` re-solves and compares without writing, so it cannot dirty the
# worktree. pre-push, not pre-commit: a mid-branch commit may legitimately
# lag the lock, but a push with a stale lock burns a CI cycle.
- id: pixi-lock-check
name: pixi.lock is in sync with the manifest
entry: pixi lock --check
language: system
pass_filenames: false
files: ^(pyproject\.toml|pixi\.toml|pixi\.lock)$
stages:
- pre-push
- id: no-hardcoded-user-paths
name: no hardcoded user-specific absolute paths
language: pygrep
entry: (/home/[A-Za-z0-9_.-]+/|/Users/[A-Za-z0-9_.-]+/|[A-Za-z]:\\Users\\)
types_or:
- python
- toml
- id: no-section-separator-comments
name: no decorative section-separator comments
language: pygrep
entry: ^\s*#\s*[-=#_*]{10,}\s*$
types:
- python
# Catches the labelled forms only — PR/issue numbers, `E<n>`/`F<n>`
# finding labels, `round-<n>`, `pre-fix`. Prose that rehearses history
# without a label stays a review responsibility.
- id: no-internal-references
name: no references a reader cannot reach from the checkout
language: pygrep
entry: (?:^|[\s(\[])\#[0-9]{2,5}\b(?!\.[0-9])|(?i:\b(?:round|wave)-[0-9]+\b)|(?i:\b(?:audit|review|finding|witness|defect|bug|fix|guard)\s+)(?:finding\s+)?[EF][0-9]{1,2}\b|\b[EF][0-9]{1,2}(?i:\s+(?:fix|guard|bug|defect|witness|signature|regression|finding|audit)\b)|(?:^|\s)\((?:the\s+)?(?!(?:F8|F16|F32|F64)\b)[EF][0-9]{1,2}['’]?(?:\s*[,/]\s*[EF][0-9]{1,2}['’]?)*(?:[,)\s])|(?i:\b(?:pre|post)-fix\b)
types:
- python
ci:
autoupdate_schedule: monthly
# pre-commit.ci has no pixi environments and blocks network at hook runtime;
# the GitHub Actions run-ty job covers type checking.
# the GitHub Actions `run-ty` job covers type checking, and pixi-lock-check
# needs a pixi binary that pre-commit.ci does not provide.
#
# `pre-push-hooks-installed` runs a file from the `.ai-instructions` submodule,
# which pre-commit.ci does not clone, and it asks about the local clone, which
# is meaningless on a runner anyway.
skip:
- ty
- pixi-lock-check
- pre-push-hooks-installed
1 change: 0 additions & 1 deletion CLAUDE.md

This file was deleted.

1 change: 0 additions & 1 deletion GEMINI.md

This file was deleted.

14 changes: 9 additions & 5 deletions docs/_generate_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ def _render(mapping: dict[str, dict]) -> str:
lines = [
"# Variables",
"",
f"{len(mapping)} final variables across {len(by_module)} modules, generated "
"from `variable_to_metadata_mapping.yaml`.",
(
f"{len(mapping)} final variables across {len(by_module)} modules, "
"generated from `variable_to_metadata_mapping.yaml`."
),
"",
"A **—** in the *Survey years* column marks a variable with no per-wave "
"availability: biographical and design modules have no `survey_year` "
"dimension.",
(
"A **—** in the *Survey years* column marks a variable with no per-wave "
"availability: biographical and design modules have no `survey_year` "
"dimension."
),
"",
]
for module in sorted(by_module):
Expand Down
64 changes: 32 additions & 32 deletions docs/concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
The SOEP is a panel survey that follows the same individuals over time. It is run in
yearly **waves**. Each wave consists of several survey **modules**, and the SOEP team
distributes each module as one **raw data file** (Stata `.dta`). For example
`hwealth.dta` holds household-level wealth; one of its variables, `p010ha`, is the market
value of the primary residence
`hwealth.dta` holds household-level wealth; one of its variables, `p010ha`, is the
market value of the primary residence
([paneldata.org/soep-core/datasets/hwealth/p010ha](https://paneldata.org/soep-core/datasets/hwealth/p010ha)).

After conversion to pandas, each module is cleaned into typed, renamed **variables**.
Expand All @@ -17,36 +17,36 @@ Variables from several modules can be combined into a new module, named

SOEP module names combine a unit prefix with a content suffix:

| Affix | Meaning |
|---|---|
| `p…` | person level |
| `h…` | household level |
| `bio…` | biographical / retrospective |
| `kid…` | children |
| `…gen` | SOEP-*generated* (cleaned, consistent) variables |
| `…brutto` | fieldwork / gross sample data (contact and response status) |
| `…pathl` | the panel *path* (tracking) file, long format |
| `…l` | long format (the yearly questionnaire data) |
| `…equiv` | cross-nationally equivalent file (CNEF), income reference = previous year |
| `…kal` | activity calendar (Kalendarium) for the previous year |
| Affix | Meaning |
| --------- | ------------------------------------------------------------------------- |
| `p…` | person level |
| `h…` | household level |
| `bio…` | biographical / retrospective |
| `kid…` | children |
| `…gen` | SOEP-*generated* (cleaned, consistent) variables |
| `…brutto` | fieldwork / gross sample data (contact and response status) |
| `…pathl` | the panel *path* (tracking) file, long format |
| `…l` | long format (the yearly questionnaire data) |
| `…equiv` | cross-nationally equivalent file (CNEF), income reference = previous year |
| `…kal` | activity calendar (Kalendarium) for the previous year |

The modules in this pipeline. Most follow the affix scheme above; `cirdef`, `design`,
and `health` are standalone files that do not:

| Module | Contents |
|---|---|
| `ppathl` / `hpathl` | person / household tracking (IDs, weights, status across waves) |
| `pgen` / `hgen` | generated person / household variables |
| `pbrutto` | fieldwork / response status per person |
| `pl` / `hl` | yearly person / household questionnaire data |
| `pequiv` | CNEF-harmonised person income and household aggregates |
| `pkal` | person activity / income calendar for the previous year |
| `pwealth` / `hwealth` | person / household wealth (multiply imputed) |
| `biobirth`, `bioparen`, `bioedu`, `biol` | fertility, parental, education, life-history biographies |
| `kidlong` | child-level information across waves |
| `cirdef` | household random-group / SOEP teaching-sample membership (optional) |
| `design` | survey sampling design (random group, stratum, sample) |
| `health` | derived SF-12 health module (physical / mental component summaries) |
| Module | Contents |
| ---------------------------------------- | ------------------------------------------------------------------- |
| `ppathl` / `hpathl` | person / household tracking (IDs, weights, status across waves) |
| `pgen` / `hgen` | generated person / household variables |
| `pbrutto` | fieldwork / response status per person |
| `pl` / `hl` | yearly person / household questionnaire data |
| `pequiv` | CNEF-harmonised person income and household aggregates |
| `pkal` | person activity / income calendar for the previous year |
| `pwealth` / `hwealth` | person / household wealth (multiply imputed) |
| `biobirth`, `bioparen`, `bioedu`, `biol` | fertility, parental, education, life-history biographies |
| `kidlong` | child-level information across waves |
| `cirdef` | household random-group / SOEP teaching-sample membership (optional) |
| `design` | survey sampling design (random group, stratum, sample) |
| `health` | derived SF-12 health module (physical / mental component summaries) |

The `cirdef` module is optional: it is only required to build the SOEP teaching sample.
If it is absent, the pipeline warns and runs without it instead of aborting.
Expand All @@ -61,8 +61,8 @@ Every cleaned module carries the identifier columns it has among `p_id`, `hh_id`
`hh_id_original`, and `survey_year`. These align modules for merging.

These are kept as **plain columns, not a pandas index**. The merged dataset feeds
GETTSIM, which expects flat columns, and a flat layout keeps merges explicit. If you want
them as an index in your own analysis, set it yourself:
GETTSIM, which expects flat columns, and a flat layout keeps merges explicit. If you
want them as an index in your own analysis, set it yourself:

```python
df = df.set_index(["p_id", "survey_year"])
Expand All @@ -80,6 +80,6 @@ before the interview is recorded as per-variable metadata, not in the name. See
Search the project for a variable name. You will find it in at least two places: its
entry in `create_metadata/variable_to_metadata_mapping.yaml` (module, dtype, available
survey years) and its definition in `clean_modules/` or `combine_modules/`. The
definition shows the raw SOEP variable(s) it is built from, which you can then look up on
paneldata.org. The [Variables](variables.md) reference lists every variable with its
definition shows the raw SOEP variable(s) it is built from, which you can then look up
on paneldata.org. The [Variables](variables.md) reference lists every variable with its
module, dtype, and available survey years.
27 changes: 14 additions & 13 deletions docs/extending.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Extending the pipeline

All cleaning follows functional data management: build the result column by column from an
empty frame, touch each variable once, one pure function per transformation, and spell out
every input column at the assignment site. Follow the [Naming conventions](naming_conventions.md)
for every new variable.
All cleaning follows functional data management: build the result column by column from
an empty frame, touch each variable once, one pure function per transformation, and
spell out every input column at the assignment site. Follow the
[Naming conventions](naming_conventions.md) for every new variable.

## Add a variable to an existing module

Expand All @@ -17,21 +17,22 @@ def clean(raw_data: pd.DataFrame) -> pd.DataFrame:
return out
```

The cleaning function takes the specific raw `pd.Series` it needs and returns the cleaned
series. Add a focused test for the cleaning function.
The cleaning function takes the specific raw `pd.Series` it needs and returns the
cleaned series. Add a focused test for the cleaning function.

## Derive a variable from several modules

`combine_modules/` holds scripts that build a variable from more than one cleaned module.
Each exposes `combine(...)` taking the cleaned modules it needs and returning a frame with
the new variable. The result is itself a module, named `{module_1}_{module_2}` (e.g.
`pequiv_pkal`). See `combine_modules/` for examples; reconcile the inputs' grain and
reference period explicitly when they differ.
`combine_modules/` holds scripts that build a variable from more than one cleaned
module. Each exposes `combine(...)` taking the cleaned modules it needs and returning a
frame with the new variable. The result is itself a module, named
`{module_1}_{module_2}` (e.g. `pequiv_pkal`). See `combine_modules/` for examples;
reconcile the inputs' grain and reference period explicitly when they differ.

## Add a new module

1. Place the raw `.dta` file in the data directory (e.g. `soep_preparation/data/V41`).
2. Create `clean_modules/<module>.py` exposing

1. Create `clean_modules/<module>.py` exposing
`clean(raw_data: pd.DataFrame) -> pd.DataFrame`:

```python
Expand All @@ -47,7 +48,7 @@ reference period explicitly when they differ.
return out
```

3. The metadata catalogue picks the module up automatically on the next `pytask` run.
1. The metadata catalogue picks the module up automatically on the next `pytask` run.

For the available cleaning helpers (dtype conversions, dummy creation, missing-code
handling, category merging), see `utilities/data_manipulator.py`.
4 changes: 2 additions & 2 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

## Install

Install [pixi](https://prefix.dev/docs/pixi/overview#installation) if you do not have it.
It manages the environment and tasks.
Install [pixi](https://prefix.dev/docs/pixi/overview#installation) if you do not have
it. It manages the environment and tasks.

## Add the raw data

Expand Down
8 changes: 4 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ Prepare German Socio-Economic Panel (SOEP-Core) survey data into typed, cleaned,
documented variables — for research and as inputs to
[GETTSIM](https://gettsim.readthedocs.io/en/stable/).

The pipeline casts each raw variable to an adequate dtype, converts SOEP missing codes to
`pd.NA`, reduces over-fine categories, combines related variables across modules into new
ones, and exposes a metadata catalogue plus a helper for assembling a final dataset. The
raw data is the SOEP-Core panel from
The pipeline casts each raw variable to an adequate dtype, converts SOEP missing codes
to `pd.NA`, reduces over-fine categories, combines related variables across modules into
new ones, and exposes a metadata catalogue plus a helper for assembling a final dataset.
The raw data is the SOEP-Core panel from
[DIW Berlin](https://www.diw.de/en/diw_01.c.678568.en/research_data_center_soep.html).

```mermaid
Expand Down
Loading
Loading