Skip to content

Commit 6ae07d7

Browse files
workaround unwanted tabulate formatting of year headers as floats
1 parent b5b7cfd commit 6ae07d7

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/geophires_x/EconomicsSam.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import PySAM.Utilityrate5 as UtilityRate
2424
from tabulate import tabulate
2525

26-
import geophires_x.Model as Model
2726
from geophires_x import Model as Model
2827
from geophires_x.EconomicsSamCashFlow import _calculate_sam_economics_cash_flow
2928
from geophires_x.Parameter import Parameter
@@ -96,7 +95,14 @@ def get_sam_cash_flow_profile_tabulated_output(model: Model, **tabulate_kw_args)
9695
Note model must have already calculated economics for this to work (used in Outputs)
9796
"""
9897

99-
_tabulate_kw_args = {'tablefmt': 'tsv', 'floatfmt': '.2f', 'intfmt': ',', **tabulate_kw_args}
98+
# fmt:off
99+
_tabulate_kw_args = {
100+
'tablefmt': 'tsv',
101+
'floatfmt': '.2f',
102+
'intfmt': ',',
103+
**tabulate_kw_args
104+
}
105+
# fmt:on
100106

101107
return tabulate(model.economics.sam_economics.value[_SAM_CASH_FLOW_PROFILE_KEY], **_tabulate_kw_args)
102108

src/geophires_x/EconomicsSamCashFlow.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ def _calculate_sam_economics_cash_flow(model: Model, single_owner: Singleowner)
2121

2222
profile = []
2323
total_duration = model.surfaceplant.plant_lifetime.value + model.surfaceplant.construction_years.value
24-
years = list(range(0, total_duration))
24+
25+
# Prefix with 'Year ' partially as workaround for tabulate applying float formatting to ints, possibly related
26+
# to https://github.com/astanin/python-tabulate/issues/18
27+
years = [f'Year {y}' for y in list(range(0, total_duration))]
28+
2529
row_1 = [None] + years
2630
profile.append(row_1)
2731

0 commit comments

Comments
 (0)