Skip to content

Fix ruff F401/I001: remove unused imports, sort import block #28

Fix ruff F401/I001: remove unused imports, sort import block

Fix ruff F401/I001: remove unused imports, sort import block #28

Workflow file for this run

name: tests
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
pytest:
name: pytest (Python ${{ matrix.python }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python: ["3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
cache: pip
- name: Install package + all optional deps
run: |
python -m pip install --upgrade pip
pip install -e ".[all,dev]"
- name: Run pytest
run: pytest tests/ -q
- name: Lint with ruff
run: ruff check src/ tests/
case-study:
# The NHANES narrative-audit notebook re-runs the full survey-weighted
# analysis end-to-end and asserts numerical agreement with R `survey`
# to ≥ 4 decimals. If any of the twelve audited PySofra seams
# regresses, the executed notebook raises and this job fails.
name: case-study (NHANES + R survey agreement)
runs-on: ubuntu-latest
needs: pytest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: pip
- name: Install package + case-study deps
run: |
python -m pip install --upgrade pip
pip install -e ".[all,dev]"
pip install jupyter nbconvert ipykernel
- name: Set up R 4.4 (with Posit Public Package Manager)
# Using the P3M repo serves pre-built Linux binaries (built
# against Ubuntu 22.04 runner libs) so we skip all source
# compilation and system-library hunting (libuv-dev, libgit2,
# cmake, etc.) that gtsummary's dep tree pulls in.
uses: r-lib/actions/setup-r@v2
with:
r-version: "4.4"
use-public-rspm: true
- name: Install R packages (binary from P3M)
uses: r-lib/actions/setup-r-dependencies@v2
with:
packages: |
any::survey
any::haven
any::jsonlite
any::dplyr
any::gtsummary
any::gt
any::broom
# Skip extra runs (this project has no DESCRIPTION).
dependencies: '"hard"'
- name: Cache NHANES download
uses: actions/cache@v4
with:
path: examples/jss_case_study/_nhanes_cache
# Bust when the script's list of files or URLs changes.
key: nhanes-${{ hashFiles('examples/jss_case_study/case_study.py') }}
- name: Execute the notebook
# `nbconvert --execute` exits non-zero on any cell error or
# AssertionError. Step 12's two asserts (machine-precision
# numerical agreement with R `survey`) are the contract.
# Step 11's `assert all(...)` enforces byte-determinism.
run: |
cd examples/jss_case_study
jupyter nbconvert --to notebook --execute --inplace \
--ExecutePreprocessor.timeout=600 \
jss_case_study.ipynb
- name: Run R cross-validation
run: |
cd examples/jss_case_study
Rscript R/cross_validate.R
- name: Re-execute notebook with R reference present
# The first execution wrote `R_reference.json`; re-running picks
# it up and the Step-12 assertions kick in. If R agreement
# has degraded, this step fails.
run: |
cd examples/jss_case_study
jupyter nbconvert --to notebook --execute --inplace \
--ExecutePreprocessor.timeout=600 \
jss_case_study.ipynb
- name: Re-render HTML
run: |
cd examples/jss_case_study
jupyter nbconvert --to html jss_case_study.ipynb
- name: Build gtsummary reference + execute comparison
# Positioning artefact: reproduces gtsummary::trial's canonical
# `tbl_summary(by=trt) |> add_p()` output in PySofra and asserts
# the Wilcoxon / chi-square p-values agree to 4 decimals.
run: |
cd examples/gtsummary_comparison
Rscript R/build_reference.R
jupyter nbconvert --to notebook --execute --inplace \
--ExecutePreprocessor.timeout=300 \
gtsummary_comparison.ipynb
jupyter nbconvert --to html gtsummary_comparison.ipynb
- name: Upload executed artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: case-study-${{ github.sha }}
path: |
examples/jss_case_study/jss_case_study.ipynb
examples/jss_case_study/jss_case_study.html
examples/jss_case_study/R_reference.json
examples/gtsummary_comparison/gtsummary_comparison.ipynb
examples/gtsummary_comparison/gtsummary_comparison.html
examples/gtsummary_comparison/gtsummary.json
examples/gtsummary_comparison/gtsummary.html
retention-days: 30