From 627fed3c50cc0af1520048e92a9135f803424368 Mon Sep 17 00:00:00 2001 From: Echedey Luis <80125792+echedey-ls@users.noreply.github.com> Date: Mon, 1 Jun 2026 04:35:57 +0200 Subject: [PATCH] Fix all styles violations after linter switch to Ruff --- .../use_perez_modelchain.py | 1 - pvlib/singlediode.py | 22 +++++++++---------- pvlib/spa.py | 4 ++-- pvlib/spectrum/mismatch.py | 2 -- pvlib/tracking.py | 2 +- tests/iotools/test_midc.py | 3 +-- tests/test_clearsky.py | 2 +- tests/test_pvsystem.py | 14 ++++++------ 8 files changed, 23 insertions(+), 27 deletions(-) diff --git a/docs/examples/irradiance-transposition/use_perez_modelchain.py b/docs/examples/irradiance-transposition/use_perez_modelchain.py index dd0d12f2a5..0346ec32c4 100644 --- a/docs/examples/irradiance-transposition/use_perez_modelchain.py +++ b/docs/examples/irradiance-transposition/use_perez_modelchain.py @@ -22,7 +22,6 @@ # This example shows how the :py:class:`~pvlib.modelchain.ModelChain` can # be adjusted to use a different set of Perez coefficients. -import pandas as pd from pvlib.pvsystem import PVSystem from pvlib.modelchain import ModelChain from pvlib.temperature import TEMPERATURE_MODEL_PARAMETERS diff --git a/pvlib/singlediode.py b/pvlib/singlediode.py index 974d59dff8..a95ed24466 100644 --- a/pvlib/singlediode.py +++ b/pvlib/singlediode.py @@ -768,12 +768,12 @@ def _lambertw_v_from_i(current, photocurrent, saturation_current, # Ensure that we are working with read-only views of numpy arrays # Turns Series into arrays so that we don't have to worry about # multidimensional broadcasting failing - I, IL, I0, Rs, Gsh, a = \ + Iop, IL, I0, Rs, Gsh, a = \ np.broadcast_arrays(current, photocurrent, saturation_current, resistance_series, conductance_shunt, nNsVth) - # Intitalize output V (I might not be float64) - V = np.full_like(I, np.nan, dtype=np.float64) + # Intitalize output Vop (Iop might not be float64) + Vop = np.full_like(Iop, np.nan, dtype=np.float64) # Determine indices where 0 < Gsh requires implicit model solution idx_p = 0. < Gsh @@ -783,14 +783,14 @@ def _lambertw_v_from_i(current, photocurrent, saturation_current, # Explicit solutions where Gsh=0 if np.any(idx_z): - V[idx_z] = a[idx_z] * np.log1p((IL[idx_z] - I[idx_z]) / I0[idx_z]) - \ - I[idx_z] * Rs[idx_z] + Vop[idx_z] = a[idx_z] * np.log1p((IL[idx_z] - Iop[idx_z]) / I0[idx_z]) - \ + Iop[idx_z] * Rs[idx_z] # Only compute using LambertW if there are cases with Gsh>0 if np.any(idx_p): # use only the relevant subset for what follows - I = I[idx_p] + Iop = Iop[idx_p] IL = IL[idx_p] I0 = I0[idx_p] Rs = Rs[idx_p] @@ -800,7 +800,7 @@ def _lambertw_v_from_i(current, photocurrent, saturation_current, # LambertW argument, cannot be float128, may overflow to np.inf # overflow is explicitly handled below, so ignore warnings here with np.errstate(over='ignore'): - argW = I0 / (Gsh * a) * np.exp((-I + IL + I0) / (Gsh * a)) + argW = I0 / (Gsh * a) * np.exp((-Iop + IL + I0) / (Gsh * a)) lambertwterm = np.zeros_like(argW) @@ -814,19 +814,19 @@ def _lambertw_v_from_i(current, photocurrent, saturation_current, # Calculate using log(argW) in case argW is really big logargW = (np.log(I0[idx_inf]) - np.log(Gsh[idx_inf]) - np.log(a[idx_inf]) + - (-I[idx_inf] + IL[idx_inf] + I0[idx_inf]) / + (-Iop[idx_inf] + IL[idx_inf] + I0[idx_inf]) / (Gsh[idx_inf] * a[idx_inf])) lambertwterm[idx_inf] = _log_lambertw(logargW) # Eqn. 3 in Jain and Kapoor, 2004 # V = -I*(Rs + Rsh) + IL*Rsh - a*lambertwterm + I0*Rsh # Recast in terms of Gsh=1/Rsh for better numerical stability. - V[idx_p] = (IL + I0 - I) / Gsh - I * Rs - a * lambertwterm + Vop[idx_p] = (IL + I0 - Iop) / Gsh - Iop * Rs - a * lambertwterm if output_is_scalar: - return V.item() + return Vop.item() else: - return V + return Vop def _lambertw_i_from_v(voltage, photocurrent, saturation_current, diff --git a/pvlib/spa.py b/pvlib/spa.py index fe072b2cc9..a25388cccd 100644 --- a/pvlib/spa.py +++ b/pvlib/spa.py @@ -472,8 +472,8 @@ def heliocentric_longitude(jme): l_rad = (l0 + l1 * jme + l2 * jme**2 + l3 * jme**3 + l4 * jme**4 + l5 * jme**5)/10**8 - l = np.rad2deg(l_rad) - return l % 360 + l_deg = np.rad2deg(l_rad) + return l_deg % 360 @jcompile('float64(float64)', nopython=True) def heliocentric_latitude(jme): diff --git a/pvlib/spectrum/mismatch.py b/pvlib/spectrum/mismatch.py index 830c0be171..610b9ce56b 100644 --- a/pvlib/spectrum/mismatch.py +++ b/pvlib/spectrum/mismatch.py @@ -9,8 +9,6 @@ import pandas as pd from scipy.integrate import trapezoid -from warnings import warn - def calc_spectral_mismatch_field(sr, e_sun, e_ref=None): """ diff --git a/pvlib/tracking.py b/pvlib/tracking.py index 69c679ef79..e234887cd0 100644 --- a/pvlib/tracking.py +++ b/pvlib/tracking.py @@ -1,7 +1,7 @@ import numpy as np import pandas as pd -from pvlib.tools import cosd, sind, tand, acosd, asind +from pvlib.tools import cosd, sind, tand, acosd from pvlib import irradiance from pvlib import shading from pvlib._deprecation import renamed_kwarg_warning diff --git a/tests/iotools/test_midc.py b/tests/iotools/test_midc.py index 636550d23c..03bfd423f9 100644 --- a/tests/iotools/test_midc.py +++ b/tests/iotools/test_midc.py @@ -1,6 +1,5 @@ import pandas as pd import pytest -import pytz from pvlib.iotools import midc from tests.conftest import TESTS_DATA_DIR, RERUNS, RERUNS_DELAY @@ -34,7 +33,7 @@ def test_midc__format_index(): start = start.tz_localize("MST") end = pd.Timestamp("20181014 23:59") end = end.tz_localize("MST") - assert type(data.index) == pd.DatetimeIndex + assert isinstance(data.index, pd.DatetimeIndex) assert data.index[0] == start assert data.index[-1] == end diff --git a/tests/test_clearsky.py b/tests/test_clearsky.py index 687dd9133e..2e4b595a8e 100644 --- a/tests/test_clearsky.py +++ b/tests/test_clearsky.py @@ -575,7 +575,7 @@ def test_clearsky_get_threshold_raises_error(): def test_detect_clearsky_calls_threshold(mocker, detect_clearsky_threshold_data): threshold_spy = mocker.spy(clearsky, '_clearsky_get_threshold') expected, cs = detect_clearsky_threshold_data - threshold_actual = clearsky.detect_clearsky(expected['GHI'], cs['ghi'], + _ = clearsky.detect_clearsky(expected['GHI'], cs['ghi'], infer_limits=True) assert threshold_spy.call_count == 1 diff --git a/tests/test_pvsystem.py b/tests/test_pvsystem.py index 267d3b14c9..e43130fb61 100644 --- a/tests/test_pvsystem.py +++ b/tests/test_pvsystem.py @@ -1298,18 +1298,18 @@ def test_v_from_i(fixture_v_from_i, method, atol): Rsh = fixture_v_from_i['Rsh'] Rs = fixture_v_from_i['Rs'] nNsVth = fixture_v_from_i['nNsVth'] - I = fixture_v_from_i['I'] + Iop = fixture_v_from_i['I'] I0 = fixture_v_from_i['I0'] IL = fixture_v_from_i['IL'] V_expected = fixture_v_from_i['V_expected'] - V = pvsystem.v_from_i(I, IL, I0, Rs, Rsh, nNsVth, method=method) + Vop = pvsystem.v_from_i(Iop, IL, I0, Rs, Rsh, nNsVth, method=method) - assert isinstance(V, type(V_expected)) - if isinstance(V, np.ndarray): - assert isinstance(V.dtype, type(V_expected.dtype)) - assert V.shape == V_expected.shape - assert_allclose(V, V_expected, atol=atol) + assert isinstance(Vop, type(V_expected)) + if isinstance(Vop, np.ndarray): + assert isinstance(Vop.dtype, type(V_expected.dtype)) + assert Vop.shape == V_expected.shape + assert_allclose(Vop, V_expected, atol=atol) def test_i_from_v_from_i(fixture_v_from_i):