Skip to content

Commit

Permalink
Add daily unit tests (#502)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenBarrettQC committed Jan 3, 2022
1 parent 96a2be5 commit fd38196
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 3 deletions.
29 changes: 29 additions & 0 deletions .github/actions/daily_unittests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Run image
description: Run private container from GitHub Packages Registry after Docker login
inputs:
python_version:
description: 'Python version'
required: true
pandas_version:
description: 'Pandas version'
required: true
numpy_version:
description: 'Numpy version'
required: true
scikit_version:
description: 'Scikit-learn version'
required: true
scipy_version:
description: 'Scipy version'
required: true
tabmat_version:
description: 'Tabmat version'
required: true
runs:
using: 'docker'
image: condaforge/mambaforge:latest
args:
- /bin/bash
- "-l"
- "-c"
- "PYTHON_VERSION=${{ inputs.python_version }} PANDAS_VERSION=${{ inputs.pandas_version }} NUMPY_VERSION=${{ inputs.numpy_version }} SCIKIT_VERSION=${{ inputs.scikit_version }} SCIPY_VERSION=${{ inputs.scipy_version }} TABMAT_VERSION=${{ inputs.tabmat_version }} ./.github/workflows/test_daily.sh"
72 changes: 72 additions & 0 deletions .github/workflows/daily.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Daily runs
on:
schedule:
- cron: '0 5 * * *'
push:
paths:
- '.github/workflows/daily.yml'

jobs:
linux-daily-unittests:
name: "Linux - daily unit tests - Python ${{ matrix.PYTHON_VERSION}} - ${{ matrix.NOTE }}"
runs-on: ubuntu-latest
env:
CI: True
strategy:
fail-fast: false
matrix:
include:
- PYTHON_VERSION: '3.9'
PANDAS_VERSION: 'nightly'
NUMPY_VERSION: 'nightly'
# See https://github.com/Quantco/glum/issues/506
# SCIKIT_VERSION: 'nightly'
SCIKIT_VERSION: ''
SCIPY_VERSION: 'nightly'
TABMAT_VERSION: 'nightly'
NOTE: 'Nightly Builds' # run once with nightlies
- PYTHON_VERSION: '3.9'
PANDAS_VERSION: ''
NUMPY_VERSION: ''
SCIKIT_VERSION: ''
SCIPY_VERSION: ''
TABMAT_VERSION: ''
NOTE: 'Default Builds' # run once with normal dependencies
steps:
- name: Pull image
run: docker pull condaforge/mambaforge:latest
- name: Checkout branch
uses: actions/checkout@v2.3.5
with:
ref: ${{ github.head_ref }}
- name: Run CI inside of container
uses: ./.github/actions/daily_unittests
with:
python_version: ${{ matrix.PYTHON_VERSION }}
pandas_version: ${{ matrix.PANDAS_VERSION }}
numpy_version: ${{ matrix.NUMPY_VERSION }}
scikit_version: ${{ matrix.SCIKIT_VERSION }}
scipy_version: ${{ matrix.SCIPY_VERSION }}
tabmat_version: ${{ matrix.TABMAT_VERSION }}
- name: Issue on failure
uses: actions/github-script@v5
if: ${{ failure() }}
with:
script: |
github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: "open",
labels: "[bot] Daily run"
}).then((issues) => {
if (issues.data.length === 0){
github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: "Daily run failure: Unit tests",
body: "The daily unit tests failed. See https://github.com/Quantco/glum/actions/runs/${{ github.run_id }} for details.",
assignees: ["MarcAntoineSchmidtQC", "lbittarello"],
labels: ["[bot] Daily run"]
})
}
});
74 changes: 74 additions & 0 deletions .github/workflows/test_daily.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/bash

set -exo pipefail

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source ${SCRIPT_DIR}/base.sh "$PYTHON_VERSION"

mamba install -y yq

cat environment.yml > /tmp/environment.yml

# pin version of some libraries, if specified
LIBRARIES=("python" "pandas" "numpy" "scikit" "scipy" "tabmat")
for library in "${LIBRARIES[@]}"; do
varname="${library^^}_VERSION"
version=${!varname}
if [[ -n "$version" && "$version" != "nightly" ]]; then
if [[ "${library}" == "scikit" ]]; then
library="scikit-learn"
fi
yq -Y --in-place ". + {dependencies: [.dependencies[], \"${library}=${version}\"]}" /tmp/environment.yml
fi
done

cat /tmp/environment.yml

mamba env create -f /tmp/environment.yml
mamba env update -n $(yq -r .name environment.yml) --file environment-benchmark.yml
conda activate $(yq -r .name environment.yml)

# This needs to be done before any 'uninstall --force'
if [[ "$TABMAT_VERSION" == "nightly" ]]; then
echo "Install compilation dependencies"
mamba install -y c-compiler cxx-compiler cython jemalloc-local libgomp mako xsimd
fi

PRE_WHEELS="https://pypi.anaconda.org/scipy-wheels-nightly/simple"
if [[ "$NUMPY_VERSION" == "nightly" ]]; then
echo "Installing Numpy nightly"
conda uninstall -y --force numpy
pip install --pre --no-deps --upgrade --timeout=60 -i $PRE_WHEELS numpy
fi
if [[ "$PANDAS_VERSION" == "nightly" ]]; then
echo "Installing Pandas nightly"
conda uninstall -y --force pandas
pip install --pre --no-deps --upgrade --timeout=60 -i $PRE_WHEELS pandas
fi
if [[ "$SCIKIT_VERSION" == "nightly" ]]; then
echo "Install scikit-learn nightly"
conda uninstall -y --force scikit-learn
pip install --pre --no-deps --upgrade --timeout=60 -i $PRE_WHEELS scikit-learn
fi
if [[ "$SCIPY_VERSION" == "nightly" ]]; then
echo "Installing Scipy nightly"
conda uninstall -y --force scipy
pip install --pre --no-deps --upgrade --timeout=60 -i $PRE_WHEELS scipy
fi
if [[ "$TABMAT_VERSION" == "nightly" ]]; then
echo "Install tabmat nightly"
# TODO: switch to a special channel once we have a Quetz instance up and running
conda uninstall -y --force tabmat
pip install git+https://github.com/Quantco/tabmat
fi

pip install --no-use-pep517 --no-deps --disable-pip-version-check -e .
pytest -nauto tests --doctest-modules src/

# Check that the readme example will work by running via doctest.
# We run outside the repo to make the test a bit more similar to
# a user running after installing with conda.
mkdir ../temp
cp README.md ../temp
cd ../temp
python -m doctest -v README.md
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Changelog

- The :meth:`score` method of :class:`~glum.GeneralizedLinearRegressor` and :class:`~glum.GeneralizedLinearRegressorCV` now accepts offsets.

**Other:**

- The CI now runs daily unit tests against the nightly builds of numpy, pandas and scikit-learn.

2.0.3 - 2021-11-05
------------------

Expand Down
2 changes: 1 addition & 1 deletion src/glum/_glm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ def report_diagnostics(
import pandas as pd

print("Diagnostics:")
with pd.option_context("max_rows", None, "max_columns", None):
with pd.option_context("display.max_rows", None, "display.max_columns", None):
print(diagnostics)

def get_formatted_diagnostics(
Expand Down
7 changes: 6 additions & 1 deletion src/glum_benchmarks/bench_glum.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ def glum_bench(
result["best_alpha"] = m.alpha_

with pd.option_context(
"display.expand_frame_repr", False, "max_columns", None, "max_rows", None
"display.expand_frame_repr",
False,
"display.max_columns",
None,
"display.max_rows",
None,
):
if diagnostics_level == "basic":
m.report_diagnostics()
Expand Down
7 changes: 6 additions & 1 deletion src/glum_benchmarks/cli_analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ def cli_analyze(
)

with pd.option_context(
"display.expand_frame_repr", False, "max_columns", None, "max_rows", None
"display.expand_frame_repr",
False,
"display.max_columns",
None,
"display.max_rows",
None,
):
if cols is not None:
cols_to_show = _get_comma_sep_names(cols)
Expand Down

0 comments on commit fd38196

Please sign in to comment.