Skip to content

Commit

Permalink
Fix Windows/Conda CI error in test_singlediode.py (#2007)
Browse files Browse the repository at this point in the history
* Update test_singlediode.py

* Linter 🔧

* Update test_singlediode.py

* Change approach completely. Now we are mocking. 👷

* Thanks ruff for the formatting 💚
  • Loading branch information
echedey-ls authored Apr 15, 2024
1 parent 71da245 commit c2ac022
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions pvlib/tests/test_singlediode.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
bishop88, bishop88_i_from_v, bishop88_v_from_i)
from pvlib._deprecation import pvlibDeprecationWarning
import pytest
from numpy.testing import assert_array_equal
from .conftest import DATA_DIR

POA = 888
Expand Down Expand Up @@ -167,17 +168,24 @@ def test_singlediode_precision(method, precise_iv_curves):
assert np.allclose(pc['i_xx'], outs['i_xx'], atol=1e-6, rtol=0)


def test_singlediode_lambert_negative_voc():

# Those values result in a negative v_oc out of `_lambertw_v_from_i`
x = np.array([0., 1.480501e-11, 0.178, 8000., 1.797559])
outs = pvsystem.singlediode(*x, method='lambertw')
assert outs['v_oc'] == 0
def test_singlediode_lambert_negative_voc(mocker):
"""Tests approximation to zero of v_oc when it is negative and small.
See singlediode.py:_lambertw > comment 'Set small elements <0 in v_oc to 0'
"""
# Next values should result in a negative v_oc out of `_lambertw_v_from_i`
# however, we can't ensure that the output belongs to (-1e-12, 0), so we
# mock it. It depends on the platform and Python distro. See issue #2000.
patcher = mocker.patch("pvlib.singlediode._lambertw_v_from_i")
x = np.array([0.0, 1.480501e-11, 0.178, 8000.0, 1.797559])
patcher.return_value = -9.999e-13
outs = pvsystem.singlediode(*x, method="lambertw")
assert outs["v_oc"] == 0

# Testing for an array
x = np.array([x, x]).T
outs = pvsystem.singlediode(*x, method='lambertw')
assert np.array_equal(outs['v_oc'], [0, 0])
patcher.return_value = np.array([-9.999e-13, -1.001e-13])
x = np.array([x, x]).T
outs = pvsystem.singlediode(*x, method="lambertw")
assert_array_equal(outs["v_oc"], [0, 0])


@pytest.mark.parametrize('method', ['lambertw'])
Expand Down

0 comments on commit c2ac022

Please sign in to comment.