Skip to content

Commit 07e47ec

Browse files
committed
reprs
1 parent 6b770a1 commit 07e47ec

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

pvlib/pvsystem.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from pvlib._deprecation import deprecated
1616

1717
from pvlib import (atmosphere, iam, inverter, irradiance,
18-
singlediode as _singlediode, temperature, tracking)
18+
singlediode as _singlediode, temperature, tools)
1919
from pvlib.tools import _build_kwargs
2020
from pvlib._deprecation import pvlibDeprecationWarning
2121

@@ -1129,14 +1129,12 @@ def __init__(self,
11291129

11301130
self.name = name
11311131

1132-
def __repr__(self):
1132+
def __repr__(self, name='BaseArray'):
11331133
attrs = ['name', 'module',
11341134
'albedo', 'racking_model', 'module_type',
11351135
'temperature_model_parameters',
11361136
'strings', 'modules_per_string']
1137-
return 'BaseArray:\n ' + '\n '.join(
1138-
f'{attr}: {getattr(self, attr)}' for attr in attrs
1139-
)
1137+
return tools.repr(self, attrs, name=name, level=1)
11401138

11411139
def _extend_repr(self, name, attributes):
11421140
"""refactor into non-cringy super() gymnastics"""
@@ -1321,7 +1319,7 @@ def __init__(
13211319
racking_model=None,
13221320
name=None
13231321
):
1324-
1322+
self.name = name
13251323
self.surface_tilt = surface_tilt
13261324
self.surface_azimuth = surface_azimuth
13271325

@@ -1339,8 +1337,10 @@ def __init__(
13391337
)
13401338

13411339
def __repr__(self):
1342-
attrs = ['surface_tilt', 'surface_azimuth']
1343-
return self._extend_repr('FixedTiltArray', attrs)
1340+
parent_repr = super().__repr__(name='FixedArray')
1341+
attrs = ['name', 'surface_tilt', 'surface_azimuth']
1342+
this_repr = tools.repr(self, attrs, level=1)
1343+
return parent_repr + '\n' + this_repr
13441344

13451345
def get_aoi(self, solar_zenith, solar_azimuth):
13461346
"""
@@ -1521,6 +1521,7 @@ def __init__(
15211521
name=None
15221522
):
15231523

1524+
self.name = name
15241525
self.axis_tilt = axis_tilt
15251526
self.axis_azimuth = axis_azimuth
15261527
self.max_angle = max_angle
@@ -1542,9 +1543,11 @@ def __init__(
15421543
)
15431544

15441545
def __repr__(self):
1545-
attrs = ['axis_tilt', 'axis_azimuth', 'max_angle', 'backtrack', 'gcr',
1546-
'cross_axis_tilt']
1547-
return self._extend_repr('SingleAxisArray', attrs)
1546+
parent_repr = super().__repr__(name='SingleAxisArray')
1547+
attrs = ['name', 'axis_tilt', 'axis_azimuth', 'max_angle', 'backtrack',
1548+
'gcr', 'cross_axis_tilt']
1549+
this_repr = tools.repr(self, attrs, level=1)
1550+
return parent_repr + '\n' + this_repr
15481551

15491552
def singleaxis(self, apparent_zenith, apparent_azimuth):
15501553
"""
@@ -1563,6 +1566,7 @@ def singleaxis(self, apparent_zenith, apparent_azimuth):
15631566
-------
15641567
tracking data
15651568
"""
1569+
from pvlib import tracking
15661570
tracking_data = tracking.singleaxis(
15671571
apparent_zenith, apparent_azimuth,
15681572
self.axis_tilt, self.axis_azimuth,

pvlib/tools.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,15 @@ def _golden_sect_DataFrame(params, VL, VH, func):
318318
raise Exception("EXCEPTION:iterations exceeded maximum (50)")
319319

320320
return func(df, 'V1'), df['V1']
321+
322+
323+
def repr(obj, attributes, name=None, level=1):
324+
if name is not None:
325+
prefix = ' ' * (level - 1)
326+
this_repr = f'{prefix}{name}:\n'
327+
else:
328+
this_repr = ''
329+
indent = ' ' * level
330+
this_repr += '\n'.join(
331+
f'{indent}{attr}: {getattr(obj, attr)}' for attr in attributes)
332+
return this_repr

0 commit comments

Comments
 (0)