Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor formatting changes to CS tables #50

Merged
merged 3 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cs-config/cs_config/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,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 @@ -420,6 +420,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 @@ -470,10 +478,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