Skip to content

Commit

Permalink
Merge pull request #50 from Peter-Metz/format
Browse files Browse the repository at this point in the history
Minor formatting changes to CS tables
  • Loading branch information
Peter-Metz authored Oct 21, 2020
2 parents e796e3a + 9dda513 commit e5dbc61
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cs-config/cs_config/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ def comp_output(crunch, df_base, df_reform, span, mtr_opt):
detail = crunch.calc_table()

table_basic = basic.to_html(
classes="table table-striped table-hover"
classes="table table-striped table-hover text-right"
)
table_detail = detail.to_html(
classes="table table-striped table-hover"
classes="table table-striped table-hover text-right"
)

comp_dict = {
Expand Down
19 changes: 17 additions & 2 deletions taxcrunch/cruncher.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,14 @@ def basic_table(self):
]
)
self.df_basic = self.df_basic.round(2)

self.df_basic.iloc[0, :] = self.df_basic.iloc[0, :].apply(
lambda x: "{:,.2f}".format(x)
)
self.df_basic.iloc[2, :] = self.df_basic.iloc[2, :].apply(
lambda x: "{:,.2f}".format(x)
)

return self.df_basic

def calc_table(self):
Expand Down Expand Up @@ -479,10 +487,17 @@ def calc_table(self):
df_calc_mtr = self.calc_mtr.dataframe(calculation).transpose()

self.df_calc = pd.concat([df_calc1, df_calc2, df_calc_mtr], axis=1)
self.df_calc.columns = ["Base", "Reform", "+ $1 ({})".format(self.mtr_options)]

mtr_label = "+ $1 ({})".format(self.mtr_options)

self.df_calc.columns = ["Base", "Reform", mtr_label]
self.df_calc.index = labels

self.df_calc = self.df_calc.round(2)
self.df_calc.Base = self.df_calc.Base.apply(lambda x: "{:,.2f}".format(x))
self.df_calc.Reform = self.df_calc.Reform.apply(lambda x: "{:,.2f}".format(x))
self.df_calc.iloc[:, 2] = self.df_calc.iloc[:, 2].apply(
lambda x: "{:,.2f}".format(x)
)

return self.df_calc

Expand Down
5 changes: 4 additions & 1 deletion taxcrunch/tests/test_cruncher.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ def test_basic_table(cr_data):

def test_calc_table(cr_data):
table = cr_data.calc_table()
# remove commas and convert to numeric
table = table.replace(',','',regex=True)
for col in table.columns:
table[col] = table[col].apply(pd.to_numeric)
assert isinstance(table, pd.DataFrame)
assert table.iloc[0]["Reform"] + 1 == table.iloc[0]["+ $1 (Taxpayer Earnings)"]
table_path = os.path.join(CURR_PATH, "expected_calc_table.csv")
# table.to_csv(table_path)
expected_table = pd.read_csv(table_path, index_col=0)
Expand Down

0 comments on commit e5dbc61

Please sign in to comment.