-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Matching Python types for return values of pvsystem.calcparams_*
#1700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f36d832
8d184fe
2842a77
95553fb
c188743
993243e
44a2a6a
fabb4eb
3cb6845
96b558b
aeaf065
0547ed7
dd2f64b
ac91f3b
8612500
43945f3
d86bc10
5d4f6d4
05a7de6
6bfc361
5e4c16c
0ff0f45
370ae3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
from pvlib import (atmosphere, iam, inverter, irradiance, | ||
singlediode as _singlediode, spectrum, temperature) | ||
from pvlib.tools import _build_kwargs, _build_args | ||
import pvlib.tools as tools | ||
|
||
|
||
# a dict of required parameter names for each DC power model | ||
|
@@ -1913,7 +1914,7 @@ def calcparams_desoto(effective_irradiance, temp_cell, | |
saturation_current : numeric | ||
Diode saturation curent in amperes | ||
|
||
resistance_series : float | ||
resistance_series : numeric | ||
Series resistance in ohms | ||
|
||
resistance_shunt : numeric | ||
|
@@ -2036,9 +2037,21 @@ def calcparams_desoto(effective_irradiance, temp_cell, | |
# use errstate to silence divide by warning | ||
with np.errstate(divide='ignore'): | ||
Rsh = R_sh_ref * (irrad_ref / effective_irradiance) | ||
|
||
Rs = R_s | ||
|
||
return IL, I0, Rs, Rsh, nNsVth | ||
numeric_args = (effective_irradiance, temp_cell) | ||
out = (IL, I0, Rs, Rsh, nNsVth) | ||
|
||
if all(map(np.isscalar, numeric_args)): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. np.isscalar docs suggest that we should instead test if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the goal of |
||
return out | ||
|
||
index = tools.get_pandas_index(*numeric_args) | ||
|
||
if index is None: | ||
return np.broadcast_arrays(*out) | ||
|
||
return tuple(pd.Series(a, index=index).rename(None) for a in out) | ||
|
||
|
||
def calcparams_cec(effective_irradiance, temp_cell, | ||
|
@@ -2117,7 +2130,7 @@ def calcparams_cec(effective_irradiance, temp_cell, | |
saturation_current : numeric | ||
Diode saturation curent in amperes | ||
|
||
resistance_series : float | ||
resistance_series : numeric | ||
Series resistance in ohms | ||
|
||
resistance_shunt : numeric | ||
|
@@ -2234,7 +2247,7 @@ def calcparams_pvsyst(effective_irradiance, temp_cell, | |
saturation_current : numeric | ||
Diode saturation current in amperes | ||
|
||
resistance_series : float | ||
resistance_series : numeric | ||
Series resistance in ohms | ||
|
||
resistance_shunt : numeric | ||
|
@@ -2293,7 +2306,18 @@ def calcparams_pvsyst(effective_irradiance, temp_cell, | |
|
||
Rs = R_s | ||
|
||
return IL, I0, Rs, Rsh, nNsVth | ||
numeric_args = (effective_irradiance, temp_cell) | ||
out = (IL, I0, Rs, Rsh, nNsVth) | ||
|
||
if all(map(np.isscalar, numeric_args)): | ||
return out | ||
|
||
index = tools.get_pandas_index(*numeric_args) | ||
|
||
if index is None: | ||
return np.broadcast_arrays(*out) | ||
|
||
return tuple(pd.Series(a, index=index).rename(None) for a in out) | ||
|
||
|
||
def retrieve_sam(name=None, path=None): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"the same Python type" - this suggests to me that
type(output) == type(input)
in every case. This isn't actually tested and I'd be slightly surprised if there are no scalar-ish numpy gotchas.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sentence in the whatsnew is not exactly correct. In this PR, the
calcparams_*
functions decide the Python type of the return values checking these conditions in order:calcparams_*
are scalars (as determined bynp.isscalar
), then return values are scalars. Sinceeffective_irradiance
andtemp_cell
are the only numeric-types, and the other arguments arefloat
, this condition only depends on the types ofeffective_irradiance
andtemp_cell
.effective_irradiance
ortemp_cell
is apd.Series
, then return values have typepd.Series
.effective_irradiance
ortemp_cell
is and.ndarray
, then return values have typenp.ndarray
. This includes 0d-arrays.I added tests to check the return values' Python type here.