Skip to content

Commit

Permalink
save actual diffs to folder
Browse files Browse the repository at this point in the history
  • Loading branch information
jdebacker committed Nov 3, 2023
1 parent 57d65c6 commit 64b4e1c
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions taxcalc/validation/taxsim35/main_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
import pandas as pd
import tc_sims

CUR_PATH = os.path.abspath(os.path.dirname(__file__))
# check if directory exists, if not create it
if not os.path.isdir(os.path.join(CUR_PATH, "actual_differences")):
os.mkdir(os.path.join(CUR_PATH, "actual_differences"))


def main(letter, year):
# (1) generate TAXSIM-35-formatted output using Tax-Calculator tc CLI
Expand All @@ -26,8 +31,6 @@ def main(letter, year):
# skipinitialspace=True,
index_col=0,
)
print("tax sim head = ", taxsim_df.head())
print("tax calc head = ", taxcalc_df.head())

taxsim_out_cols_map = {
"taxsimid": "RECID",
Expand Down Expand Up @@ -99,7 +102,7 @@ def main(letter, year):
# delim_whitespace=True,
index_col=False,
)
with pd.ExcelWriter(f"{letter}{year}differences.xlsx") as writer:
with pd.ExcelWriter(os.path.join(CUR_PATH, "actual_differences", f"{letter}{year}differences.xlsx")) as writer:
# use to_excel function and specify the sheet_name and index
# to store the dataframe in specified sheet
taxsim_df.to_excel(writer, sheet_name="taxsim", index=False)
Expand Down Expand Up @@ -135,8 +138,9 @@ def main(letter, year):
print(actual_df)

# (3) check for difference between LYY.taxdiffs-actual and LYY.taxdiffs-expect
if os.path.isfile(f"{letter}{year}-taxdiffs-expect.csv"):
expect_df = pd.read_csv(f"{letter}{year}-taxdiffs-expect.csv", index_col=0)
expected_file_name = os.path.join(CUR_PATH, "expected_differences", f"{letter}{year}-taxdiffs-expect.csv")
if os.path.isfile(expected_file_name):
expect_df = pd.read_csv(expected_file_name, index_col=0)

print(actual_df.eq(expect_df))

Expand All @@ -148,7 +152,7 @@ def main(letter, year):
print("This EXPECT file doesn't exist.")

# (4) Write the created df to *.taxdiffs-actual
actual_df.to_csv(f"{letter}{year}-taxdiffs-actual.csv")
actual_df.to_csv(os.path.join(CUR_PATH, "actual_differences", f"{letter}{year}-taxdiffs-actual.csv"))


if __name__ == "__main__":
Expand Down

0 comments on commit 64b4e1c

Please sign in to comment.