From 64b4e1c9d96717df79e60e64676f5ba657aa35e2 Mon Sep 17 00:00:00 2001 From: jdebacker Date: Fri, 3 Nov 2023 18:03:18 -0400 Subject: [PATCH] save actual diffs to folder --- taxcalc/validation/taxsim35/main_comparison.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/taxcalc/validation/taxsim35/main_comparison.py b/taxcalc/validation/taxsim35/main_comparison.py index a1d15536c..9f30f3d1c 100644 --- a/taxcalc/validation/taxsim35/main_comparison.py +++ b/taxcalc/validation/taxsim35/main_comparison.py @@ -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 @@ -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", @@ -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) @@ -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)) @@ -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__":