Skip to content

Commit 3da6024

Browse files
Replace all instances of OrderedDict with dict (#2855)
* replace OrderedDict with dict everywhere * whatsnew * Update tests/test_pvsystem.py Co-authored-by: Echedey Luis <80125792+echedey-ls@users.noreply.github.com> --------- Co-authored-by: Echedey Luis <80125792+echedey-ls@users.noreply.github.com>
1 parent 53f9341 commit 3da6024

9 files changed

Lines changed: 75 additions & 61 deletions

File tree

docs/sphinx/source/contributing/style_guide.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ allows for multiple input types to work for many parameters. pvlib uses
5858
the following generic descriptors as short-hand to indicate which
5959
specific types may be used:
6060

61-
* dict-like : dict, OrderedDict, pd.Series
61+
* dict-like : dict, pd.Series
6262
* numeric : scalar, np.array, pd.Series. Typically int or float dtype.
6363
* array-like : np.array, pd.Series. Typically int or float dtype.
6464

docs/sphinx/source/user_guide/modeling_topics/clearsky.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ A clear sky time series using only basic pvlib functions.
297297

298298

299299
The input data types determine the returned output type. Array input
300-
results in an OrderedDict of array output, and Series input results in a
300+
results in an dict of array output, and Series input results in a
301301
DataFrame output. The keys are 'ghi', 'dni', and 'dhi'.
302302

303303
Grid with a clear sky irradiance for a few turbidity values.
@@ -437,7 +437,7 @@ A clear sky time series using only basic pvlib functions.
437437
In [1]: plt.close();
438438

439439
The input data types determine the returned output type. Array input
440-
results in an OrderedDict of array output, and Series input results in a
440+
results in an dict of array output, and Series input results in a
441441
DataFrame output. The keys are 'ghi', 'dni', and 'dhi'.
442442

443443
Irradiance as a function of solar elevation.
@@ -518,7 +518,7 @@ Contour plots of irradiance as a function of both PW and AOD.
518518

519519
In [1]: aod700, precipitable_water = np.meshgrid(aod700, precipitable_water)
520520

521-
# inputs are arrays, so solis is an OrderedDict
521+
# inputs are arrays, so solis is an dict
522522
In [1]: solis = clearsky.simplified_solis(apparent_elevation, aod700,
523523
...: precipitable_water, pressure,
524524
...: dni_extra)

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,25 @@ Breaking Changes
3434
and :py:func:`pvlib.iam.schlick_diffuse` from tuple to ``dict``, to be
3535
consistent with :py:func:`pvlib.iam.marion_diffuse`. (:issue:`2837`,
3636
:pull:`2842`)
37+
* All ``OrderedDict`` outputs are now ``dict``. The following functions
38+
are affected (:issue:`1684`, :pull:`2856`):
39+
40+
* :py:func:`~pvlib.clearsky.ineichen`
41+
* :py:func:`~pvlib.clearsky.simplified_solis`
42+
* :py:func:`~pvlib.clearsky.detect_clearsky`
43+
* :py:func:`~pvlib.clearsky.bird`
44+
* :py:func:`~pvlib.irradiance.disc`
45+
* :py:func:`~pvlib.irradiance.gti_dirint`
46+
* :py:func:`~pvlib.irradiance.erbs`
47+
* :py:func:`~pvlib.irradiance.erbs_driesse`
48+
* :py:func:`~pvlib.irradiance.orgill_hollands`
49+
* :py:func:`~pvlib.irradiance.boland`
50+
* :py:func:`~pvlib.irradiance.campbell_norman`
51+
* :py:func:`~pvlib.irradiance.louche`
52+
* :py:func:`~pvlib.pvsystem.sapm`
53+
* :py:func:`~pvlib.pvsystem.max_power_point`
54+
55+
3756

3857
Deprecations
3958
~~~~~~~~~~~~

pvlib/clearsky.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"""
55

66
import os
7-
from collections import OrderedDict
87
import calendar
98

109
import numpy as np
@@ -56,7 +55,7 @@ def ineichen(apparent_zenith, airmass_absolute, linke_turbidity,
5655
5756
Returns
5857
-------
59-
clearsky : DataFrame (if Series input) or OrderedDict of arrays
58+
clearsky : DataFrame (if Series input) or dict of arrays
6059
Contains the columns/keys ``'dhi', 'dni', 'ghi'``, with the same
6160
unit as the input parameter ``dni_extra``.
6261
@@ -138,7 +137,7 @@ def ineichen(apparent_zenith, airmass_absolute, linke_turbidity,
138137

139138
dhi = ghi - dni*cos_zenith
140139

141-
irrads = OrderedDict()
140+
irrads = {}
142141
irrads['ghi'] = ghi
143142
irrads['dni'] = dni
144143
irrads['dhi'] = dhi
@@ -363,8 +362,8 @@ def simplified_solis(apparent_elevation, aod700=0.1, precipitable_water=1.,
363362
364363
Returns
365364
-------
366-
clearsky : DataFrame (if Series input) or OrderedDict of arrays
367-
DataFrame/OrderedDict contains the columns/keys
365+
clearsky : DataFrame (if Series input) or dict of arrays
366+
DataFrame/dict contains the columns/keys
368367
``'dhi', 'dni', 'ghi'``.
369368
370369
References
@@ -408,7 +407,7 @@ def simplified_solis(apparent_elevation, aod700=0.1, precipitable_water=1.,
408407
ghi = i0p * np.exp(-taug/sin_elev**g) * sin_elev
409408
dhi = i0p * np.exp(-taud/sin_elev**d)
410409

411-
irrads = OrderedDict()
410+
irrads = {}
412411
irrads['ghi'] = ghi
413412
irrads['dni'] = dni
414413
irrads['dhi'] = dhi
@@ -737,7 +736,7 @@ def detect_clearsky(measured, clearsky, times=None, infer_limits=False,
737736
Boolean array or Series of whether or not the given time is
738737
clear. Return type is the same as the input type.
739738
740-
components : OrderedDict, optional
739+
components : dict, optional
741740
Dict of arrays of whether or not the given time window is clear
742741
for each condition. Only provided if ``return_components`` is True.
743742
@@ -905,7 +904,7 @@ def detect_clearsky(measured, clearsky, times=None, infer_limits=False,
905904
clear_samples = pd.Series(clear_samples, index=times)
906905

907906
if return_components:
908-
components = OrderedDict()
907+
components = {}
909908
components['mean_diff_flag'] = c1
910909
components['max_diff_flag'] = c2
911910
components['line_length_flag'] = c3
@@ -971,8 +970,8 @@ def bird(zenith, airmass_relative, aod380, aod500, precipitable_water,
971970
972971
Returns
973972
-------
974-
clearsky : DataFrame (if Series input) or OrderedDict of arrays
975-
DataFrame/OrderedDict contains the columns/keys
973+
clearsky : DataFrame (if Series input) or dict of arrays
974+
DataFrame/dict contains the columns/keys
976975
``'dhi', 'dni', 'ghi', 'direct_horizontal'`` in [W/m^2].
977976
978977
See also
@@ -1039,8 +1038,8 @@ def bird(zenith, airmass_relative, aod380, aod500, precipitable_water,
10391038
gh = (id_nh + ias) / (1.0 - albedo * rs)
10401039
diffuse_horiz = gh - id_nh
10411040
# TODO: be DRY, use decorator to wrap methods that need to return either
1042-
# OrderedDict or DataFrame instead of repeating this boilerplate code
1043-
irrads = OrderedDict()
1041+
# dict or DataFrame instead of repeating this boilerplate code
1042+
irrads = {}
10441043
irrads['direct_horizontal'] = id_nh
10451044
irrads['ghi'] = gh
10461045
irrads['dni'] = id_

pvlib/irradiance.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"""
66

77
import datetime
8-
from collections import OrderedDict
98
from functools import partial
109

1110
import numpy as np
@@ -1958,7 +1957,7 @@ def disc(ghi, solar_zenith, datetime_or_doy, pressure=101325,
19581957
19591958
Returns
19601959
-------
1961-
output : OrderedDict or DataFrame
1960+
output : dict or DataFrame
19621961
Contains the following keys:
19631962
19641963
* ``dni``: The modeled direct normal irradiance
@@ -2000,7 +1999,7 @@ def disc(ghi, solar_zenith, datetime_or_doy, pressure=101325,
20001999
bad_values = (solar_zenith > max_zenith) | (ghi < 0) | (dni < 0)
20012000
dni = np.where(bad_values, 0, dni)
20022001

2003-
output = OrderedDict()
2002+
output = {}
20042003
output['dni'] = dni
20052004
output['kt'] = kt
20062005
output['airmass'] = am
@@ -2479,7 +2478,7 @@ def gti_dirint(poa_global, aoi, solar_zenith, solar_azimuth, times,
24792478
24802479
Returns
24812480
-------
2482-
data : DataFrame
2481+
data : dict or DataFrame
24832482
Contains the following keys/columns:
24842483
24852484
* ``ghi``: the modeled global horizontal irradiance. [Wm⁻²]
@@ -2517,7 +2516,7 @@ def gti_dirint(poa_global, aoi, solar_zenith, solar_azimuth, times,
25172516
ghi_gte_90, dni_gte_90, dhi_gte_90 = np.nan, np.nan, np.nan
25182517

25192518
# put the AOI < 90 and AOI >= 90 conditions together
2520-
output = OrderedDict()
2519+
output = {}
25212520
output['ghi'] = ghi.where(aoi_lt_90, ghi_gte_90)
25222521
output['dni'] = dni.where(aoi_lt_90, dni_gte_90)
25232522
output['dhi'] = dhi.where(aoi_lt_90, dhi_gte_90)
@@ -2776,7 +2775,7 @@ def erbs(ghi, zenith, datetime_or_doy, min_cos_zenith=0.065, max_zenith=87):
27762775
27772776
Returns
27782777
-------
2779-
data : OrderedDict or DataFrame
2778+
data : dict or DataFrame
27802779
Contains the following keys/columns:
27812780
27822781
* ``dni``: the modeled direct normal irradiance. [Wm⁻²]
@@ -2823,7 +2822,7 @@ def erbs(ghi, zenith, datetime_or_doy, min_cos_zenith=0.065, max_zenith=87):
28232822
# ensure that closure relationship remains valid
28242823
dhi = np.where(bad_values, ghi, dhi)
28252824

2826-
data = OrderedDict()
2825+
data = {}
28272826
data['dni'] = dni
28282827
data['dhi'] = dhi
28292828
data['kt'] = kt
@@ -2885,7 +2884,7 @@ def erbs_driesse(ghi, zenith, datetime_or_doy=None, dni_extra=None,
28852884
28862885
Returns
28872886
-------
2888-
data : OrderedDict or DataFrame
2887+
data : dict or DataFrame
28892888
Contains the following keys/columns:
28902889
28912890
* ``dni``: the modeled direct normal irradiance. [Wm⁻²]
@@ -2960,7 +2959,7 @@ def erbs_driesse(ghi, zenith, datetime_or_doy=None, dni_extra=None,
29602959
# ensure that closure relationship remains valid
29612960
dhi = np.where(bad_values, ghi, dhi)
29622961

2963-
data = OrderedDict()
2962+
data = {}
29642963
data['dni'] = dni
29652964
data['dhi'] = dhi
29662965
data['kt'] = kt
@@ -3012,7 +3011,7 @@ def orgill_hollands(ghi, zenith, datetime_or_doy, dni_extra=None,
30123011
30133012
Returns
30143013
-------
3015-
data : OrderedDict or DataFrame
3014+
data : dict or DataFrame
30163015
Contains the following keys/columns:
30173016
30183017
* ``dni``: the modeled direct normal irradiance. [Wm⁻²]
@@ -3058,7 +3057,7 @@ def orgill_hollands(ghi, zenith, datetime_or_doy, dni_extra=None,
30583057
# ensure that closure relationship remains valid
30593058
dhi = np.where(bad_values, ghi, dhi)
30603059

3061-
data = OrderedDict()
3060+
data = {}
30623061
data['dni'] = dni
30633062
data['dhi'] = dhi
30643063
data['kt'] = kt
@@ -3113,7 +3112,7 @@ def boland(ghi, solar_zenith, datetime_or_doy, a_coeff=8.645, b_coeff=0.613,
31133112
31143113
Returns
31153114
-------
3116-
data : OrderedDict or DataFrame
3115+
data : dict or DataFrame
31173116
Contains the following keys/columns:
31183117
31193118
* ``dni``: the modeled direct normal irradiance. [Wm⁻²]
@@ -3169,7 +3168,7 @@ def boland(ghi, solar_zenith, datetime_or_doy, a_coeff=8.645, b_coeff=0.613,
31693168
# ensure that closure relationship remains valid
31703169
dhi = np.where(bad_values, ghi, dhi)
31713170

3172-
data = OrderedDict()
3171+
data = {}
31733172
data['dni'] = dni
31743173
data['dhi'] = dhi
31753174
data['kt'] = kt
@@ -3204,7 +3203,7 @@ def campbell_norman(zenith, transmittance, pressure=101325.0,
32043203
32053204
Returns
32063205
-------
3207-
irradiance: DataFrame
3206+
irradiance: dict or DataFrame
32083207
Modeled direct normal irradiance, direct horizontal irradiance,
32093208
and global horizontal irradiance. [Wm⁻²]
32103209
@@ -3223,7 +3222,7 @@ def campbell_norman(zenith, transmittance, pressure=101325.0,
32233222
dhi = 0.3 * (1.0 - tau**airmass) * dni_extra * cos_zen
32243223
ghi = dhi + dni * cos_zen
32253224

3226-
irrads = OrderedDict()
3225+
irrads = {}
32273226
irrads['ghi'] = ghi
32283227
irrads['dni'] = dni
32293228
irrads['dhi'] = dhi
@@ -3902,7 +3901,7 @@ def louche(ghi, solar_zenith, datetime_or_doy, max_zenith=90):
39023901
39033902
Returns
39043903
-------
3905-
data: OrderedDict or DataFrame
3904+
data: dict or DataFrame
39063905
Contains the following keys/columns:
39073906
39083907
* ``dni``: the modeled direct normal irradiance, see :term:`dni`.
@@ -3934,7 +3933,7 @@ def louche(ghi, solar_zenith, datetime_or_doy, max_zenith=90):
39343933
# ensure that closure relationship remains valid
39353934
dhi = np.where(bad_values, ghi, dhi)
39363935

3937-
data = OrderedDict()
3936+
data = {}
39383937
data['dni'] = dni
39393938
data['dhi'] = dhi
39403939
data['kt'] = Kt

pvlib/pvsystem.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
performance of PV modules and inverters.
44
"""
55

6-
from collections import OrderedDict
76
import functools
87
import io
98
import itertools
@@ -2262,7 +2261,7 @@ def sapm(effective_irradiance, temp_cell, module, *, temperature_ref=25,
22622261
22632262
Returns
22642263
-------
2265-
A DataFrame with the columns:
2264+
A dict or DataFrame with the columns:
22662265
22672266
* i_sc : Short-circuit current (A)
22682267
* i_mp : Current at the maximum-power point (A)
@@ -2369,7 +2368,7 @@ def sapm(effective_irradiance, temp_cell, module, *, temperature_ref=25,
23692368
# avoid repeated __getitem__
23702369
cells_in_series = module['Cells_in_Series']
23712370

2372-
out = OrderedDict()
2371+
out = {}
23732372

23742373
out['i_sc'] = (
23752374
module['Isco'] * Ee * (1 + module['Aisc']*(temp_cell -
@@ -2684,7 +2683,7 @@ def max_power_point(photocurrent, saturation_current, resistance_series,
26842683
26852684
Returns
26862685
-------
2687-
OrderedDict or pandas.DataFrame
2686+
dict or pandas.DataFrame
26882687
``(i_mp, v_mp, p_mp)``
26892688
26902689
Notes
@@ -2702,7 +2701,7 @@ def max_power_point(photocurrent, saturation_current, resistance_series,
27022701
ivp = {'i_mp': i_mp, 'v_mp': v_mp, 'p_mp': p_mp}
27032702
out = pd.DataFrame(ivp, index=photocurrent.index)
27042703
else:
2705-
out = OrderedDict()
2704+
out = {}
27062705
out['i_mp'] = i_mp
27072706
out['v_mp'] = v_mp
27082707
out['p_mp'] = p_mp

0 commit comments

Comments
 (0)