Skip to content

Commit

Permalink
Merge branch 'master' into feature/covar_cholesky_decomp
Browse files Browse the repository at this point in the history
  • Loading branch information
jagerber48 committed Nov 16, 2024
2 parents 9a4c275 + 969324d commit 7e19785
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 147 deletions.
13 changes: 3 additions & 10 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
codecov:
token: c2f0ce36-17ad-4668-bb1b-f1b72dedf3fc
comment:
after_n_builds: 9

coverage:
precision: 2
round: down
range: "90...100"
status:
project:
default:
target: auto
threshold: 2.0%
informational: true
patch:
default:
informational: true
16 changes: 9 additions & 7 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ jobs:
cd tests
python -m pytest --cov=uncertainties --cov=. --cov-report=xml --cov-report=term
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.0.1
uses: codecov/codecov-action@v4.6.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: lmfit/uncertainties
flags: ${{ matrix.os }}-${{ matrix.python-version }}
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
test_without_numpy:
name: Test without numpy
runs-on: ubuntu-latest
Expand All @@ -46,7 +47,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
python-version: 3.12
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -57,10 +58,11 @@ jobs:
python -m pytest --ignore=test_unumpy.py --ignore=test_ulinalg.py -k "not test_monte_carlo_comparison"
--cov=uncertainties --cov=. --cov-report=xml --cov-report=term
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.0.1
uses: codecov/codecov-action@v4.6.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: lmfit/uncertainties
flags: no-numpy
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
results:
# This step aggregates the results from all the tests and allows us to
# require only this single job to pass for a PR to be merged rather than
Expand Down
12 changes: 12 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,21 @@ Change Log
Unreleased
----------

Changes

- Changed how `numpy` is handled as an optional dependency. Previously,
importing a `numpy`-dependent function, like `correlated_values`,
without `numpy` installed would result in an `ImportError` at import
time. Now such a function can be imported but if the user attempts to
execute it, a `NotImplementedError` is raised indicating that the
function can't be used because `numpy` couldn't be imported.

Fixes:

- fix `readthedocs` configuration so that the build passes (#254)
- adjust `codecov.io` configuration so that minor code coverage changes will not result
in indications that tests are failing. Rather code coverage reports will be purely
informational for code reviewers. Also fix other minor configuration issues. (#270)

3.2.2 2024-July-08
-----------------------
Expand Down
54 changes: 53 additions & 1 deletion tests/test_uncertainties.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@
import math
import random # noqa

import pytest

import uncertainties.core as uncert_core
from uncertainties.core import ufloat, AffineScalarFunc, ufloat_fromstr
from uncertainties import umath
from uncertainties import (
umath,
correlated_values,
correlated_values_norm,
correlation_matrix,
)
from helpers import (
power_special_cases,
power_all_cases,
Expand All @@ -15,6 +22,12 @@
)


try:
import numpy as np
except ImportError:
np = None


def test_value_construction():
"""
Tests the various means of constructing a constant number with
Expand Down Expand Up @@ -1313,3 +1326,42 @@ def test_correlated_values_correlation_mat():
numpy.array(cov_mat),
numpy.array(uncert_core.covariance_matrix([x2, y2, z2])),
)


@pytest.mark.skipif(
np is not None,
reason="This test is only run when numpy is not installed.",
)
def test_no_numpy():
nom_values = [1, 2, 3]
std_devs = [0.1, 0.2, 0.3]
cov = [
[1, 0, 0],
[0, 1, 0],
[0, 0, 1],
]

with pytest.raises(
NotImplementedError,
match="not able to import numpy",
):
_ = correlated_values(nom_values, cov)

with pytest.raises(
NotImplementedError,
match="not able to import numpy",
):
_ = correlated_values_norm(
list(zip(nom_values, std_devs)),
cov,
)

x = ufloat(1, 0.1)
y = ufloat(2, 0.2)
z = ufloat(3, 0.3)

with pytest.raises(
NotImplementedError,
match="not able to import numpy",
):
_ = correlation_matrix([x, y, z])
Loading

0 comments on commit 7e19785

Please sign in to comment.