Skip to content

Commit d6f671b

Browse files
committed
Remove duplicate code in init methods
1 parent 5744044 commit d6f671b

File tree

2 files changed

+33
-32
lines changed

2 files changed

+33
-32
lines changed

pvlib/pvsystem.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,28 @@
5050
'pvsyst': {'freestanding': (29.0, 0), 'insulated': (15.0, 0)}
5151
}
5252

53+
54+
def _combine_localized_attributes(pvsystem=None, location=None, **kwargs):
55+
"""
56+
Get and combine attributes from the pvsystem and/or location
57+
with the rest of the kwargs.
58+
"""
59+
if pvsystem is not None:
60+
pv_dict = pvsystem.__dict__
61+
else:
62+
pv_dict = {}
63+
64+
if location is not None:
65+
loc_dict = location.__dict__
66+
else:
67+
loc_dict = {}
68+
69+
new_kwargs = dict(list(pv_dict.items()) +
70+
list(loc_dict.items()) +
71+
list(kwargs.items()))
72+
return new_kwargs
73+
74+
5375
# not sure if this belongs in the pvsystem module.
5476
# maybe something more like core.py? It may eventually grow to
5577
# import a lot more functionality from other modules.
@@ -769,22 +791,11 @@ class LocalizedPVSystem(PVSystem, Location):
769791
"""
770792
def __init__(self, pvsystem=None, location=None, **kwargs):
771793

772-
# get and combine attributes from the pvsystem and/or location
773-
# with the rest of the kwargs
774-
775-
if pvsystem is not None:
776-
pv_dict = pvsystem.__dict__
777-
else:
778-
pv_dict = {}
779-
780-
if location is not None:
781-
loc_dict = location.__dict__
782-
else:
783-
loc_dict = {}
784-
785-
new_kwargs = dict(list(pv_dict.items()) +
786-
list(loc_dict.items()) +
787-
list(kwargs.items()))
794+
new_kwargs = _combine_localized_attributes(
795+
pvsystem=pvsystem,
796+
location=location,
797+
**kwargs,
798+
)
788799

789800
PVSystem.__init__(self, **new_kwargs)
790801
Location.__init__(self, **new_kwargs)

pvlib/tracking.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pandas as pd
33

44
from pvlib.tools import cosd, sind
5+
from pvlib.pvsystem import _combine_localized_attributes
56
from pvlib.pvsystem import PVSystem
67
from pvlib.location import Location
78
from pvlib import irradiance, atmosphere
@@ -227,22 +228,11 @@ class LocalizedSingleAxisTracker(SingleAxisTracker, Location):
227228

228229
def __init__(self, pvsystem=None, location=None, **kwargs):
229230

230-
# get and combine attributes from the pvsystem and/or location
231-
# with the rest of the kwargs
232-
233-
if pvsystem is not None:
234-
pv_dict = pvsystem.__dict__
235-
else:
236-
pv_dict = {}
237-
238-
if location is not None:
239-
loc_dict = location.__dict__
240-
else:
241-
loc_dict = {}
242-
243-
new_kwargs = dict(list(pv_dict.items()) +
244-
list(loc_dict.items()) +
245-
list(kwargs.items()))
231+
new_kwargs = _combine_localized_attributes(
232+
pvsystem=pvsystem,
233+
location=location,
234+
**kwargs,
235+
)
246236

247237
SingleAxisTracker.__init__(self, **new_kwargs)
248238
Location.__init__(self, **new_kwargs)

0 commit comments

Comments
 (0)