Skip to content

Commit

Permalink
add commas to table output
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter-Metz committed Oct 21, 2020
1 parent 353ee03 commit 53678ee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
13 changes: 11 additions & 2 deletions taxcrunch/cruncher.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,10 @@ 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 +474,15 @@ 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 53678ee

Please sign in to comment.