Skip to content

Commit f07b4c2

Browse files
committed
Remove duplicate code in init methods
1 parent 24cc8c1 commit f07b4c2

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

pvlib/pvsystem.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,27 @@
4545
}
4646

4747

48+
def _combine_localized_attributes(pvsystem=None, location=None, **kwargs):
49+
"""
50+
Get and combine attributes from the pvsystem and/or location
51+
with the rest of the kwargs.
52+
"""
53+
if pvsystem is not None:
54+
pv_dict = pvsystem.__dict__
55+
else:
56+
pv_dict = {}
57+
58+
if location is not None:
59+
loc_dict = location.__dict__
60+
else:
61+
loc_dict = {}
62+
63+
new_kwargs = dict(
64+
list(pv_dict.items()) + list(loc_dict.items()) + list(kwargs.items())
65+
)
66+
return new_kwargs
67+
68+
4869
# not sure if this belongs in the pvsystem module.
4970
# maybe something more like core.py? It may eventually grow to
5071
# import a lot more functionality from other modules.
@@ -830,22 +851,11 @@ class LocalizedPVSystem(PVSystem, Location):
830851
"""
831852
def __init__(self, pvsystem=None, location=None, **kwargs):
832853

833-
# get and combine attributes from the pvsystem and/or location
834-
# with the rest of the kwargs
835-
836-
if pvsystem is not None:
837-
pv_dict = pvsystem.__dict__
838-
else:
839-
pv_dict = {}
840-
841-
if location is not None:
842-
loc_dict = location.__dict__
843-
else:
844-
loc_dict = {}
845-
846-
new_kwargs = dict(list(pv_dict.items()) +
847-
list(loc_dict.items()) +
848-
list(kwargs.items()))
854+
new_kwargs = _combine_localized_attributes(
855+
pvsystem=pvsystem,
856+
location=location,
857+
**kwargs,
858+
)
849859

850860
PVSystem.__init__(self, **new_kwargs)
851861
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)