From 3a4a05d3d60ac0fadcfbd19e33b7d0d0635766b7 Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Sun, 18 Jan 2026 15:26:54 +0530 Subject: [PATCH 1/5] Fix division-by-zero in transformer.simple_efficiency --- pvlib/transformer.py | 3 ++- tests/test_transformer.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pvlib/transformer.py b/pvlib/transformer.py index 3b66b0beb3..3fea282e2b 100644 --- a/pvlib/transformer.py +++ b/pvlib/transformer.py @@ -111,7 +111,8 @@ def simple_efficiency( b = 1 c = no_load_loss - input_power_normalized - output_power_normalized = (-b + (b**2 - 4*a*c)**0.5) / (2 * a) + disc = (b*b - 4*a*c)**0.5 + output_power_normalized = 2*c / (-b - disc) output_power = output_power_normalized * transformer_rating return output_power diff --git a/tests/test_transformer.py b/tests/test_transformer.py index 0739a9e95a..7d7a106a3b 100644 --- a/tests/test_transformer.py +++ b/tests/test_transformer.py @@ -1,4 +1,5 @@ import pandas as pd +import pytest from numpy.testing import assert_allclose @@ -58,3 +59,24 @@ def test_simple_efficiency_known_values(): *args), rating, ) + + +@pytest.mark.parametrize( + "input_power, no_load_loss, load_loss, transformer_rating, expected", + [ + (1000.0, 0.01, 0.0, 1000.0, 990.0), + ], +) +def test_simple_efficiency_zero_load_loss( + input_power, no_load_loss, load_loss, transformer_rating, expected +): + # for load_loss = 0, the model reduces to: + # P_out = P_in - L_no_load * P_nom + result = transformer.simple_efficiency( + input_power=input_power, + no_load_loss=no_load_loss, + load_loss=load_loss, + transformer_rating=transformer_rating, + ) + + assert_allclose(result, expected) From fa80f308a514707e9d10ad6ab258cbb63ef35be1 Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Sun, 18 Jan 2026 15:29:42 +0530 Subject: [PATCH 2/5] fix flake8 --- tests/test_transformer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_transformer.py b/tests/test_transformer.py index 7d7a106a3b..48f11e0a45 100644 --- a/tests/test_transformer.py +++ b/tests/test_transformer.py @@ -79,4 +79,4 @@ def test_simple_efficiency_zero_load_loss( transformer_rating=transformer_rating, ) - assert_allclose(result, expected) + assert_allclose(result, expected) From 32450f8c875b584d469d57bb511bfd8eec0a6814 Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Wed, 21 Jan 2026 22:55:04 +0530 Subject: [PATCH 3/5] Add whatsnew note for simple_efficiency division-by-zero fix --- docs/sphinx/source/whatsnew/v0.15.1.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/sphinx/source/whatsnew/v0.15.1.rst b/docs/sphinx/source/whatsnew/v0.15.1.rst index 15d9042dd7..379167bbc1 100644 --- a/docs/sphinx/source/whatsnew/v0.15.1.rst +++ b/docs/sphinx/source/whatsnew/v0.15.1.rst @@ -14,7 +14,9 @@ Deprecations Bug fixes ~~~~~~~~~ - +* Fix a division-by-zero condition in + :py:func:`~pvlib.transformer.simple_efficiency` when ``load_loss = 0``. + (:issue:`2645`) Enhancements ~~~~~~~~~~~~ @@ -42,4 +44,5 @@ Maintenance Contributors ~~~~~~~~~~~~ +* Aman Srivastava (:ghuser:`aman-coder03`) From 0b96e2438b374d5be7490931a59f0ac8e2b7b219 Mon Sep 17 00:00:00 2001 From: Aman Srivastava Date: Fri, 23 Jan 2026 09:24:29 +0530 Subject: [PATCH 4/5] fixing docs --- docs/sphinx/source/whatsnew/v0.15.1.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/sphinx/source/whatsnew/v0.15.1.rst b/docs/sphinx/source/whatsnew/v0.15.1.rst index 379167bbc1..5cd4131c85 100644 --- a/docs/sphinx/source/whatsnew/v0.15.1.rst +++ b/docs/sphinx/source/whatsnew/v0.15.1.rst @@ -15,8 +15,8 @@ Deprecations Bug fixes ~~~~~~~~~ * Fix a division-by-zero condition in - :py:func:`~pvlib.transformer.simple_efficiency` when ``load_loss = 0``. - (:issue:`2645`) + :py:func:`pvlib.transformer.simple_efficiency` when ``load_loss = 0``. + (:issue:`2645`, :pull:`2646`) Enhancements ~~~~~~~~~~~~ From a5731da2ecbe38ade6732c982d560a20bbd969ad Mon Sep 17 00:00:00 2001 From: Kevin Anderson Date: Wed, 4 Feb 2026 08:38:07 -0500 Subject: [PATCH 5/5] Update pvlib/transformer.py --- pvlib/transformer.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pvlib/transformer.py b/pvlib/transformer.py index 3fea282e2b..6b5b6208e3 100644 --- a/pvlib/transformer.py +++ b/pvlib/transformer.py @@ -111,6 +111,8 @@ def simple_efficiency( b = 1 c = no_load_loss - input_power_normalized + # alternative form of the quadratic equation to avoid + # divide-by-zero when a == 0 disc = (b*b - 4*a*c)**0.5 output_power_normalized = 2*c / (-b - disc)