Skip to content

Commit feb6134

Browse files
authored
Merge pull request #422 from light-curve/test-without-full-extras
Improve tox test configuration
2 parents 3bac584 + 9375659 commit feb6134

File tree

5 files changed

+125
-115
lines changed

5 files changed

+125
-115
lines changed

.github/workflows/test.yml

Lines changed: 79 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Test
22

3-
on: [push, pull_request, workflow_dispatch]
3+
on: [ push, pull_request, workflow_dispatch ]
44

55
jobs:
66
py_build_deps:
@@ -14,17 +14,17 @@ jobs:
1414
working-directory: light-curve
1515

1616
steps:
17-
- uses: actions/checkout@v4
18-
with:
19-
submodules: true
20-
- name: Set up Python 3.12
21-
uses: actions/setup-python@v5
22-
with:
23-
python-version: "3.12"
24-
- name: Extract build deps from pyproject.toml
25-
id: extract_from_toml
26-
run: |
27-
echo "output="$(python -c 'import tomllib; print(" ".join(tomllib.load(open("pyproject.toml", "rb"))["build-system"]["requires"]))') >> "$GITHUB_OUTPUT"
17+
- uses: actions/checkout@v4
18+
with:
19+
submodules: true
20+
- name: Set up Python 3.12
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: "3.12"
24+
- name: Extract build deps from pyproject.toml
25+
id: extract_from_toml
26+
run: |
27+
echo "output="$(python -c 'import tomllib; print(" ".join(tomllib.load(open("pyproject.toml", "rb"))["build-system"]["requires"]))') >> "$GITHUB_OUTPUT"
2828
2929
3030
test:
@@ -33,47 +33,47 @@ jobs:
3333
strategy:
3434
fail-fast: false
3535
matrix:
36-
python_minor: ['8', '9', '10', '11', '12']
36+
python_minor: [ '8', '9', '10', '11', '12' ]
3737

3838
defaults:
3939
run:
4040
working-directory: light-curve
4141

4242
steps:
43-
- uses: actions/checkout@v4
44-
with:
45-
submodules: true
46-
- name: Set up Python 3.${{ matrix.python_minor }}
47-
uses: actions/setup-python@v5
48-
with:
49-
python-version: "3.${{ matrix.python_minor }}"
50-
- name: Install tox
51-
run: pip install tox
52-
- name: Run Python tests
53-
run: tox -e py3${{ matrix.python_minor }}
43+
- uses: actions/checkout@v4
44+
with:
45+
submodules: true
46+
- name: Set up Python 3.${{ matrix.python_minor }}
47+
uses: actions/setup-python@v5
48+
with:
49+
python-version: "3.${{ matrix.python_minor }}"
50+
- name: Install tox
51+
run: pip install tox
52+
- name: Run Python tests
53+
run: tox -e py3${{ matrix.python_minor }}-base,py3${{ matrix.python_minor }}-test
5454

5555
cargo-fmt:
5656
runs-on: ubuntu-latest
5757

5858
steps:
59-
- uses: actions/checkout@v4
60-
- run: cargo fmt --manifest-path=light-curve/Cargo.toml -- --check
59+
- uses: actions/checkout@v4
60+
- run: cargo fmt --manifest-path=light-curve/Cargo.toml -- --check
6161

6262
cargo-clippy:
6363
runs-on: ubuntu-latest
6464

6565
steps:
66-
- uses: actions/checkout@v4
67-
- uses: Swatinem/rust-cache@v2
68-
with:
69-
shared-key: "${{ runner.os }}_stable-rust_cargo-clippy"
70-
workspaces: "light-curve"
71-
- run: cargo clippy --manifest-path=light-curve/Cargo.toml --all-targets -- -D warnings
66+
- uses: actions/checkout@v4
67+
- uses: Swatinem/rust-cache@v2
68+
with:
69+
shared-key: "${{ runner.os }}_stable-rust_cargo-clippy"
70+
workspaces: "light-curve"
71+
- run: cargo clippy --manifest-path=light-curve/Cargo.toml --all-targets -- -D warnings
7272

7373
coverage:
7474
runs-on: ubuntu-latest
7575

76-
needs: [py_build_deps]
76+
needs: [ py_build_deps ]
7777

7878
defaults:
7979
run:
@@ -117,7 +117,7 @@ jobs:
117117
benchmarks:
118118
runs-on: ubuntu-latest
119119

120-
needs: [py_build_deps]
120+
needs: [ py_build_deps ]
121121

122122
steps:
123123
- uses: actions/checkout@v4
@@ -147,63 +147,63 @@ jobs:
147147
msrv-build:
148148
runs-on: ubuntu-latest
149149

150-
needs: [py_build_deps]
150+
needs: [ py_build_deps ]
151151

152152
defaults:
153153
run:
154154
working-directory: light-curve
155155

156156
steps:
157-
- uses: actions/checkout@v4
158-
- name: Set up Python 3.8
159-
uses: actions/setup-python@v5
160-
with:
161-
python-version: '3.8'
162-
- name: Set up Python 3.9
163-
uses: actions/setup-python@v5
164-
with:
165-
python-version: '3.9'
166-
- name: Set up Python 3.10
167-
uses: actions/setup-python@v5
168-
with:
169-
python-version: '3.10'
170-
- name: Set up Python 3.11
171-
uses: actions/setup-python@v5
172-
with:
173-
python-version: '3.11'
174-
- name: Set up Python 3.12
175-
uses: actions/setup-python@v5
176-
with:
177-
python-version: '3.12'
178-
- name: Get minimum supported Rust version
179-
run: echo "::set-output name=msrv::$(grep '^rust-version = ' Cargo.toml | grep -o '[0-9.]\+')"
180-
id: get_msrv
181-
- uses: dtolnay/rust-toolchain@master
182-
with:
183-
toolchain: ${{ steps.get_msrv.outputs.msrv }}
184-
- uses: Swatinem/rust-cache@v2
185-
with:
186-
shared-key: "${{ runner.os }}_msrv-rust_maturin-build"
187-
workspaces: "light-curve"
188-
- name: Install build_deps
189-
run: pip install "${{ needs.py_build_deps.outputs.output }}"
190-
- name: Build
191-
run: |
192-
rustup default ${{ steps.get_msrv.outputs.msrv }}
193-
maturin build --find-interpreter
157+
- uses: actions/checkout@v4
158+
- name: Set up Python 3.8
159+
uses: actions/setup-python@v5
160+
with:
161+
python-version: '3.8'
162+
- name: Set up Python 3.9
163+
uses: actions/setup-python@v5
164+
with:
165+
python-version: '3.9'
166+
- name: Set up Python 3.10
167+
uses: actions/setup-python@v5
168+
with:
169+
python-version: '3.10'
170+
- name: Set up Python 3.11
171+
uses: actions/setup-python@v5
172+
with:
173+
python-version: '3.11'
174+
- name: Set up Python 3.12
175+
uses: actions/setup-python@v5
176+
with:
177+
python-version: '3.12'
178+
- name: Get minimum supported Rust version
179+
run: echo "::set-output name=msrv::$(grep '^rust-version = ' Cargo.toml | grep -o '[0-9.]\+')"
180+
id: get_msrv
181+
- uses: dtolnay/rust-toolchain@master
182+
with:
183+
toolchain: ${{ steps.get_msrv.outputs.msrv }}
184+
- uses: Swatinem/rust-cache@v2
185+
with:
186+
shared-key: "${{ runner.os }}_msrv-rust_maturin-build"
187+
workspaces: "light-curve"
188+
- name: Install build_deps
189+
run: pip install "${{ needs.py_build_deps.outputs.output }}"
190+
- name: Build
191+
run: |
192+
rustup default ${{ steps.get_msrv.outputs.msrv }}
193+
maturin build --find-interpreter
194194
195195
arm:
196-
runs-on: [self-hosted, linux, ARM64]
196+
runs-on: [ self-hosted, linux, ARM64 ]
197197

198-
needs: [py_build_deps]
198+
needs: [ py_build_deps ]
199199

200200
defaults:
201201
run:
202202
working-directory: light-curve
203203

204204
steps:
205-
- uses: actions/checkout@v4
206-
- name: Install build_deps
207-
run: pip install "${{ needs.py_build_deps.outputs.output }}"
208-
- name: Build
209-
run: maturin build
205+
- uses: actions/checkout@v4
206+
- name: Install build_deps
207+
run: pip install "${{ needs.py_build_deps.outputs.output }}"
208+
- name: Build
209+
run: maturin build

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2525

2626
### Fixed
2727

28-
--
28+
- Package import doesn't fail if `scipy` is missed https://github.com/light-curve/light-curve-python/pull/422
2929

3030
### Security
3131

light-curve/light_curve/light_curve_py/features/rainbow/bolometric.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from typing import Dict, List, Union
55

66
import numpy as np
7-
from scipy.special import lambertw
87

98
__all__ = [
109
"bolometric_terms",
@@ -225,7 +224,6 @@ def value(t, t0, amplitude, rise_time):
225224

226225
@staticmethod
227226
def initial_guesses(t, m, sigma, band):
228-
229227
A = np.ptp(m)
230228
med_dt = median_dt(t, band)
231229

@@ -328,6 +326,11 @@ def limits(t, m, sigma, band):
328326

329327
@staticmethod
330328
def peak_time(t0, p):
329+
try:
330+
from scipy.special import lambertw
331+
except ImportError:
332+
raise ImportError("scipy is required for DoublexpBolometricTerm.peak_time, please install it")
333+
331334
return t0 + np.real(-lambertw(p * np.exp(1)) + 1)
332335

333336

light-curve/light_curve/light_curve_py/minuit_ml.py

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,10 @@
33
from typing import Callable, Dict, Tuple
44

55
import numpy as np
6-
from scipy.special import erf
7-
8-
9-
def logpdf(x, mu, sigma):
10-
# We do not need second term as it does not depend on parameters
11-
return -(((x - mu) / sigma) ** 2) / 2 # - np.log(np.sqrt(2*np.pi) * sigma)
12-
13-
14-
def barrier(x):
15-
res = np.where(x > 0, 1 / x, np.inf) # FIXME: naive barrier function
16-
17-
return res
18-
19-
20-
def logcdf(x):
21-
# TODO: faster (maybe not so accurate, as we do not need it) implementation
22-
# return norm.logcdf(x)
23-
24-
result = np.zeros(len(x))
25-
26-
idx = x < -5
27-
result[idx] = -x[idx] ** 2 / 2 - 1 / x[idx] ** 2 - 0.9189385336 - np.log(-x[idx])
28-
result[~idx] = np.log(0.5) + np.log1p(erf(x[~idx] / np.sqrt(2)))
29-
30-
return result
31-
326

337
try:
348
from iminuit import Minuit
9+
from scipy.special import erf
3510
except ImportError:
3611
MaximumLikelihood = None
3712
else:
@@ -63,21 +38,47 @@ def __call__(self, *par):
6338
ym = self.model(self.x, *par)
6439

6540
if self.upper_mask is None:
66-
result = -np.sum(logpdf(self.y, ym, self.yerror))
41+
result = -np.sum(self.logpdf(self.y, ym, self.yerror))
6742
else:
6843
# Measurements
69-
result = -np.sum(logpdf(self.y[~self.upper_mask], ym[~self.upper_mask], self.yerror[~self.upper_mask]))
44+
result = -np.sum(
45+
self.logpdf(self.y[~self.upper_mask], ym[~self.upper_mask], self.yerror[~self.upper_mask])
46+
)
7047
# Upper limits, Tobit model
7148
# https://stats.stackexchange.com/questions/49443/how-to-model-this-odd-shaped-distribution-almost-a-reverse-j
7249
result += -np.sum(
73-
logcdf((self.y[self.upper_mask] - ym[self.upper_mask]) / self.yerror[self.upper_mask])
50+
self.logcdf((self.y[self.upper_mask] - ym[self.upper_mask]) / self.yerror[self.upper_mask])
7451
)
7552

7653
# Barriers around parameter ranges
7754
# Scale is selected so that for the most of the range it is much smaller
7855
# than 0.5 which corresponds to 1-sigma errors
79-
result += 0.0001 * np.sum(barrier((par - self.limits0) / self.limits_scale))
80-
result += 0.0001 * np.sum(barrier((self.limits1 - par) / self.limits_scale))
56+
result += 0.0001 * np.sum(self.barrier((par - self.limits0) / self.limits_scale))
57+
result += 0.0001 * np.sum(self.barrier((self.limits1 - par) / self.limits_scale))
58+
59+
return result
60+
61+
@staticmethod
62+
def logpdf(x, mu, sigma):
63+
# We do not need the second term as it does not depend on parameters
64+
return -(((x - mu) / sigma) ** 2) / 2 # - np.log(np.sqrt(2*np.pi) * sigma)
65+
66+
@staticmethod
67+
def barrier(x):
68+
res = np.where(x > 0, 1 / x, np.inf) # FIXME: naive barrier function
69+
70+
return res
71+
72+
@staticmethod
73+
def logcdf(x):
74+
# TODO: faster (maybe not so accurate, as we do not need it) implementation
75+
# return norm.logcdf(x)
76+
77+
result = np.zeros(len(x))
78+
79+
idx = x < -5
80+
result[idx] = -x[idx] ** 2 / 2 - 1 / x[idx] ** 2 - 0.9189385336 - np.log(-x[idx])
81+
result[~idx] = np.log(0.5) + np.log1p(erf(x[~idx] / np.sqrt(2)))
8182

8283
return result
8384

light-curve/pyproject.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,16 @@ markers = [
159159
[tool.tox]
160160
legacy_tox_ini = """
161161
[tox]
162-
envlist = py38,py39,py310,py311,py312
162+
envlist = py{38,39,310,311,312}-{base,test}
163163
isolated_build = True
164164
165-
[testenv]
165+
[testenv:py{38,39,310,311,312}-base]
166+
change_dir = {envtmpdir}
167+
extras =
168+
commands =
169+
python -c 'import light_curve'
170+
171+
[testenv:py{38,39,310,311,312}-test]
166172
extras = dev
167173
commands =
168174
pytest README.md tests/ light_curve/

0 commit comments

Comments
 (0)