Skip to content

Commit 0bc5a53

Browse files
reepoicwhanse
andauthored
Matching Python types for return values of pvsystem.calcparams_* (#1700)
* two decorators for renaming pd.Series in a function * calcparams_* Rs return value to match temp_cell type * adding tests for pd.Series naming and resistance_series type conversion * methods for converting between numeric-type values * adding more tests and clarifying documentation * rename pdSeries clear name decorator and move it to pvlib.tools * adding support for scalar to np.ndarray of any shape * updating match_shape docstring * fixing syntax error * fix stickler issues * different approach * remove unnecessary asserts * remove file * update whatsnew * add tests for all scalar inputs, and pass np.arrays to assert_allclose * Update docs/sphinx/source/whatsnew/v0.10.0.rst Co-authored-by: Cliff Hansen <[email protected]> * if condition swap, tests for tools.get_pandas_index, tests for returned Python type * fix typo in docstring * correct calcparams_cec test, and add test for calcparams_pvsyst all scalars --------- Co-authored-by: Cliff Hansen <[email protected]>
1 parent 19467f3 commit 0bc5a53

File tree

5 files changed

+343
-64
lines changed

5 files changed

+343
-64
lines changed

docs/sphinx/source/whatsnew/v0.10.0.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ Deprecations
2929

3030
Enhancements
3131
~~~~~~~~~~~~
32+
* The return values of :py:func:`pvlib.pvsystem.calcparams_desoto`,
33+
:py:func:`pvlib.pvsystem.calcparams_cec`, and
34+
:py:func:`pvlib.pvsystem.calcparams_pvsyst` are all numeric types and have
35+
the same Python type as the `effective_irradiance` and `temp_cell` parameters. (:issue:`1626`, :pull:`1700`)
36+
3237
* Added `map_variables` parameter to :py:func:`pvlib.iotools.read_srml`
3338
and :py:func:`pvlib.iotools.read_srml_month_from_solardat` (:pull:`1773`)
3439
* Allow passing keyword arguments to :py:func:`scipy:scipy.optimize.brentq` and

pvlib/pvsystem.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from pvlib import (atmosphere, iam, inverter, irradiance,
2222
singlediode as _singlediode, spectrum, temperature)
2323
from pvlib.tools import _build_kwargs, _build_args
24+
import pvlib.tools as tools
2425

2526

2627
# a dict of required parameter names for each DC power model
@@ -1540,7 +1541,7 @@ def calcparams_desoto(effective_irradiance, temp_cell,
15401541
saturation_current : numeric
15411542
Diode saturation curent in amperes
15421543
1543-
resistance_series : float
1544+
resistance_series : numeric
15441545
Series resistance in ohms
15451546
15461547
resistance_shunt : numeric
@@ -1663,9 +1664,21 @@ def calcparams_desoto(effective_irradiance, temp_cell,
16631664
# use errstate to silence divide by warning
16641665
with np.errstate(divide='ignore'):
16651666
Rsh = R_sh_ref * (irrad_ref / effective_irradiance)
1667+
16661668
Rs = R_s
16671669

1668-
return IL, I0, Rs, Rsh, nNsVth
1670+
numeric_args = (effective_irradiance, temp_cell)
1671+
out = (IL, I0, Rs, Rsh, nNsVth)
1672+
1673+
if all(map(np.isscalar, numeric_args)):
1674+
return out
1675+
1676+
index = tools.get_pandas_index(*numeric_args)
1677+
1678+
if index is None:
1679+
return np.broadcast_arrays(*out)
1680+
1681+
return tuple(pd.Series(a, index=index).rename(None) for a in out)
16691682

16701683

16711684
def calcparams_cec(effective_irradiance, temp_cell,
@@ -1744,7 +1757,7 @@ def calcparams_cec(effective_irradiance, temp_cell,
17441757
saturation_current : numeric
17451758
Diode saturation curent in amperes
17461759
1747-
resistance_series : float
1760+
resistance_series : numeric
17481761
Series resistance in ohms
17491762
17501763
resistance_shunt : numeric
@@ -1861,7 +1874,7 @@ def calcparams_pvsyst(effective_irradiance, temp_cell,
18611874
saturation_current : numeric
18621875
Diode saturation current in amperes
18631876
1864-
resistance_series : float
1877+
resistance_series : numeric
18651878
Series resistance in ohms
18661879
18671880
resistance_shunt : numeric
@@ -1920,7 +1933,18 @@ def calcparams_pvsyst(effective_irradiance, temp_cell,
19201933

19211934
Rs = R_s
19221935

1923-
return IL, I0, Rs, Rsh, nNsVth
1936+
numeric_args = (effective_irradiance, temp_cell)
1937+
out = (IL, I0, Rs, Rsh, nNsVth)
1938+
1939+
if all(map(np.isscalar, numeric_args)):
1940+
return out
1941+
1942+
index = tools.get_pandas_index(*numeric_args)
1943+
1944+
if index is None:
1945+
return np.broadcast_arrays(*out)
1946+
1947+
return tuple(pd.Series(a, index=index).rename(None) for a in out)
19241948

19251949

19261950
def retrieve_sam(name=None, path=None):

0 commit comments

Comments
 (0)