From 94dd4f6e0d882663ef5a79e933952774c11d6aea Mon Sep 17 00:00:00 2001 From: Mitch Date: Wed, 26 Mar 2025 09:56:04 -0400 Subject: [PATCH 01/13] Fix setup for usage of TMD microdata - TaxCalculator tmd_constructor() now uses 'growfactors' instead of 'gfactors' - Reference TMD files for weights and growfactors --- taxbrain/taxbrain.py | 61 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/taxbrain/taxbrain.py b/taxbrain/taxbrain.py index 52d37c6..2e4b719 100644 --- a/taxbrain/taxbrain.py +++ b/taxbrain/taxbrain.py @@ -15,7 +15,7 @@ from taxbrain.corporate_incidence import distribute as dist_corp from typing import Union from paramtools import ValidationError - +from pathlib import Path class TaxBrain: @@ -30,6 +30,11 @@ class TaxBrain: "Behavioral-Responses": behresp.__version__, } + # add expected TMD filenames as constants + TMD_DATA_FILE = "tmd.csv.gz" + TMD_WEIGHTS_FILE = "tmd_weights.csv.gz" + TMD_GROWFACTORS_FILE = "tmd_growfactors.csv" + def __init__( self, start_year: int, @@ -689,9 +694,18 @@ def _make_calculators(self): weights=tc.Records.PUF_WEIGHTS_FILENAME, ) elif self.microdata == "TMD": + # Load TMD-specific growfactors instead of default + if self.params["growdiff_baseline"]: + # Apply any user growdiff to TMD growfactors + gf_base = tc.GrowFactors(self.TMD_GROWFACTORS_FILE) + gd_base.apply_to(gf_base) + else: + gf_base = tc.GrowFactors(self.TMD_GROWFACTORS_FILE) + records = tc.Records.tmd_constructor( - "tmd.csv", - gfactors=gf_base, + data_path=Path(self.TMD_DATA_FILE), + weights_path=Path(self.TMD_WEIGHTS_FILE), + growfactors=gf_base ) elif isinstance(self.microdata, dict): if self.microdata["growfactors"] is None: @@ -740,9 +754,18 @@ def _make_calculators(self): weights=tc.Records.PUF_WEIGHTS_FILENAME, ) elif self.microdata == "TMD": + # Load TMD-specific growfactors instead of default + if self.params["growdiff_response"]: + # Apply any user growdiff to TMD growfactors + gf_reform = tc.GrowFactors(self.TMD_GROWFACTORS_FILE) + gd_reform.apply_to(gf_reform) + else: + gf_reform = tc.GrowFactors(self.TMD_GROWFACTORS_FILE) + records = tc.Records.tmd_constructor( - "tmd.csv", - gfactors=gf_reform, + data_path=Path(self.TMD_DATA_FILE), + weights_path=Path(self.TMD_WEIGHTS_FILE), + growfactors=gf_reform ) elif isinstance(self.microdata, dict): if self.microdata["growfactors"] is None: @@ -809,9 +832,18 @@ def _make_stacked_objects(self): weights=tc.Records.PUF_WEIGHTS_FILENAME, ) elif self.microdata == "TMD": + # Load TMD-specific growfactors instead of default + if self.params["growdiff_baseline"]: + # Apply any user growdiff to TMD growfactors + gf_base = tc.GrowFactors(self.TMD_GROWFACTORS_FILE) + gd_base.apply_to(gf_base) + else: + gf_base = tc.GrowFactors(self.TMD_GROWFACTORS_FILE) + records = tc.Records.tmd_constructor( - "tmd.csv", - gfactors=gf_base, + data_path=Path(self.TMD_DATA_FILE), + weights_path=Path(self.TMD_WEIGHTS_FILE), + growfactors=gf_base ) elif isinstance(self.microdata, dict): if self.microdata["growfactors"] is None: @@ -863,9 +895,18 @@ def _make_stacked_objects(self): weights=tc.Records.PUF_WEIGHTS_FILENAME, ) elif self.microdata == "TMD": - records = tc.Records.tmd_constructor( - "tmd.csv", - gfactors=gf_reform, + # Load TMD-specific growfactors instead of default + if self.params["growdiff_response"]: + # Apply any user growdiff to TMD growfactors + gf_reform = tc.GrowFactors(self.TMD_GROWFACTORS_FILE) + gd_reform.apply_to(gf_reform) + else: + gf_reform = tc.GrowFactors(self.TMD_GROWFACTORS_FILE) + + reform_records = tc.Records.tmd_constructor( + data_path=Path(self.TMD_DATA_FILE), + weights_path=Path(self.TMD_WEIGHTS_FILE), + growfactors=gf_reform ) elif isinstance(self.microdata, dict): if self.microdata["growfactors"] is None: From aa0f601ec31aff757b1368bf171a24fa4f47f856 Mon Sep 17 00:00:00 2001 From: Mitch Date: Thu, 27 Mar 2025 08:24:00 -0400 Subject: [PATCH 02/13] Reduce repetition in TMD setup blocks --- taxbrain/taxbrain.py | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/taxbrain/taxbrain.py b/taxbrain/taxbrain.py index 2e4b719..c075f44 100644 --- a/taxbrain/taxbrain.py +++ b/taxbrain/taxbrain.py @@ -694,13 +694,9 @@ def _make_calculators(self): weights=tc.Records.PUF_WEIGHTS_FILENAME, ) elif self.microdata == "TMD": - # Load TMD-specific growfactors instead of default + gf_base = tc.GrowFactors(self.TMD_GROWFACTORS_FILE) if self.params["growdiff_baseline"]: - # Apply any user growdiff to TMD growfactors - gf_base = tc.GrowFactors(self.TMD_GROWFACTORS_FILE) gd_base.apply_to(gf_base) - else: - gf_base = tc.GrowFactors(self.TMD_GROWFACTORS_FILE) records = tc.Records.tmd_constructor( data_path=Path(self.TMD_DATA_FILE), @@ -754,13 +750,9 @@ def _make_calculators(self): weights=tc.Records.PUF_WEIGHTS_FILENAME, ) elif self.microdata == "TMD": - # Load TMD-specific growfactors instead of default + gf_reform = tc.GrowFactors(self.TMD_GROWFACTORS_FILE) if self.params["growdiff_response"]: - # Apply any user growdiff to TMD growfactors - gf_reform = tc.GrowFactors(self.TMD_GROWFACTORS_FILE) gd_reform.apply_to(gf_reform) - else: - gf_reform = tc.GrowFactors(self.TMD_GROWFACTORS_FILE) records = tc.Records.tmd_constructor( data_path=Path(self.TMD_DATA_FILE), @@ -832,13 +824,9 @@ def _make_stacked_objects(self): weights=tc.Records.PUF_WEIGHTS_FILENAME, ) elif self.microdata == "TMD": - # Load TMD-specific growfactors instead of default + gf_base = tc.GrowFactors(self.TMD_GROWFACTORS_FILE) if self.params["growdiff_baseline"]: - # Apply any user growdiff to TMD growfactors - gf_base = tc.GrowFactors(self.TMD_GROWFACTORS_FILE) gd_base.apply_to(gf_base) - else: - gf_base = tc.GrowFactors(self.TMD_GROWFACTORS_FILE) records = tc.Records.tmd_constructor( data_path=Path(self.TMD_DATA_FILE), @@ -895,13 +883,9 @@ def _make_stacked_objects(self): weights=tc.Records.PUF_WEIGHTS_FILENAME, ) elif self.microdata == "TMD": - # Load TMD-specific growfactors instead of default + gf_reform = tc.GrowFactors(self.TMD_GROWFACTORS_FILE) if self.params["growdiff_response"]: - # Apply any user growdiff to TMD growfactors - gf_reform = tc.GrowFactors(self.TMD_GROWFACTORS_FILE) gd_reform.apply_to(gf_reform) - else: - gf_reform = tc.GrowFactors(self.TMD_GROWFACTORS_FILE) reform_records = tc.Records.tmd_constructor( data_path=Path(self.TMD_DATA_FILE), From 434aa145fedd1d609574d259fd5c467236efe7fb Mon Sep 17 00:00:00 2001 From: Jason DeBacker Date: Sat, 6 Dec 2025 15:39:17 -0500 Subject: [PATCH 03/13] update param names for more recent taxcalc --- taxbrain/tests/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/taxbrain/tests/conftest.py b/taxbrain/tests/conftest.py index 50f0e0c..56bf9e7 100644 --- a/taxbrain/tests/conftest.py +++ b/taxbrain/tests/conftest.py @@ -12,8 +12,8 @@ def reform_json_str(): reform = """ { "policy": { - "SS_thd50": {"2019": [50000, 100000, 50000, 50000, 50000]}, - "SS_thd85": {"2019": [50000, 100000, 50000, 50000, 50000]}, + "SS_thd1": {"2019": [50000, 100000, 50000, 50000, 50000]}, + "SS_thd2": {"2019": [50000, 100000, 50000, 50000, 50000]}, "SS_Earnings_thd": {"2019": 400000}, "FICA_ss_trt_employee": {"2020": 0.0625, "2021": 0.063, From 62b1b2f21f4e908b484e1a56a4a54b18adcf70ac Mon Sep 17 00:00:00 2001 From: Jason DeBacker Date: Sat, 6 Dec 2025 15:41:15 -0500 Subject: [PATCH 04/13] pin jupyterbook to less than 2.0 --- .github/workflows/check_jupyterbook.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check_jupyterbook.yml b/.github/workflows/check_jupyterbook.yml index 58e2afe..51311b0 100644 --- a/.github/workflows/check_jupyterbook.yml +++ b/.github/workflows/check_jupyterbook.yml @@ -21,7 +21,7 @@ jobs: - name: Build # Build Jupyter Book shell: bash -l {0} run: | - pip install jupyter-book + pip install "jupyter-book<2.0.0" pip install -e . python -m ipykernel install --user --name=taxbrain-dev cd docs From aa6c524ffe8cc87d6827eb04aab1367f9eba4b72 Mon Sep 17 00:00:00 2001 From: Jason DeBacker Date: Thu, 11 Dec 2025 10:22:55 -0500 Subject: [PATCH 05/13] use tc constructor classes --- taxbrain/taxbrain.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/taxbrain/taxbrain.py b/taxbrain/taxbrain.py index c075f44..76c432c 100644 --- a/taxbrain/taxbrain.py +++ b/taxbrain/taxbrain.py @@ -689,9 +689,10 @@ def _make_calculators(self): if self.microdata == "CPS": records = tc.Records.cps_constructor(data=None, gfactors=gf_base) elif self.microdata == "PUF": - records = tc.Records( + records = tc.Records.puf_constructor( + data="puf.csv", gfactors=gf_base, - weights=tc.Records.PUF_WEIGHTS_FILENAME, + # weights=tc.Records.PUF_WEIGHTS_FILENAME, ) elif self.microdata == "TMD": gf_base = tc.GrowFactors(self.TMD_GROWFACTORS_FILE) @@ -745,9 +746,10 @@ def _make_calculators(self): if self.microdata == "CPS": records = tc.Records.cps_constructor(data=None, gfactors=gf_reform) elif self.microdata == "PUF": - records = tc.Records( + records = tc.Records.puf_constructor( + data="puf.csv", gfactors=gf_reform, - weights=tc.Records.PUF_WEIGHTS_FILENAME, + # weights=tc.Records.PUF_WEIGHTS_FILENAME, ) elif self.microdata == "TMD": gf_reform = tc.GrowFactors(self.TMD_GROWFACTORS_FILE) @@ -818,10 +820,10 @@ def _make_stacked_objects(self): if self.microdata == "CPS": records = tc.Records.cps_constructor(data=None, gfactors=gf_base) elif self.microdata == "PUF": - records = tc.Records( - "puf.csv", + records = tc.Records.puf_constructor( + data="puf.csv", gfactors=gf_base, - weights=tc.Records.PUF_WEIGHTS_FILENAME, + # weights=tc.Records.PUF_WEIGHTS_FILENAME, ) elif self.microdata == "TMD": gf_base = tc.GrowFactors(self.TMD_GROWFACTORS_FILE) @@ -877,10 +879,10 @@ def _make_stacked_objects(self): data=None, gfactors=gf_reform ) elif self.microdata == "PUF": - reform_records = tc.Records( - "puf.csv", + reform_records = tc.Records.puf_constructor( + data="puf.csv", gfactors=gf_reform, - weights=tc.Records.PUF_WEIGHTS_FILENAME, + # weights=tc.Records.PUF_WEIGHTS_FILENAME, ) elif self.microdata == "TMD": gf_reform = tc.GrowFactors(self.TMD_GROWFACTORS_FILE) From ab9810a1f2a416442ae54d6df9a7d08a89952654 Mon Sep 17 00:00:00 2001 From: Jason DeBacker Date: Thu, 11 Dec 2025 10:23:04 -0500 Subject: [PATCH 06/13] pins for package versions --- .github/workflows/deploy_jupyterbook.yml | 2 +- environment.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy_jupyterbook.yml b/.github/workflows/deploy_jupyterbook.yml index 4e23609..fcc53b4 100644 --- a/.github/workflows/deploy_jupyterbook.yml +++ b/.github/workflows/deploy_jupyterbook.yml @@ -24,7 +24,7 @@ jobs: - name: Build # Build Jupyter Book shell: bash -l {0} run: | - pip install jupyter-book + pip install "jupyter-book<2.0.0" pip install -e . python -m ipykernel install --user --name=taxbrain-dev cd docs diff --git a/environment.yml b/environment.yml index 51acf0d..5476c7c 100644 --- a/environment.yml +++ b/environment.yml @@ -3,7 +3,7 @@ channels: - conda-forge dependencies: - python>=3.6.5 -- taxcalc>=3.0.0 +- taxcalc>=6.0.0 - behresp>=0.11.0 - pandas>=0.23 - numpy>=1.14 From 7c4f7581fa077b454dd3cd3b39bc90cfe9d226ca Mon Sep 17 00:00:00 2001 From: Jason DeBacker Date: Thu, 11 Dec 2025 11:28:36 -0500 Subject: [PATCH 07/13] fix path to cps weights --- cs-config/cs_config/functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cs-config/cs_config/functions.py b/cs-config/cs_config/functions.py index 65d3c77..bced702 100644 --- a/cs-config/cs_config/functions.py +++ b/cs-config/cs_config/functions.py @@ -154,7 +154,7 @@ def run_model(meta_params_dict, adjustment): sampling_seed = 180 full_sample = pd.read_csv(input_path) data_start_year = taxcalc.Records.CPSCSV_YEAR - weights = taxcalc.Records.CPS_WEIGHTS_FILENAME + weights = os.path.join(taxcalc.Records.CODE_PATH, 'cps_weights.csv.gz') else: raise ValueError( f"Data source '{meta_params.data_source}' is not supported." From 373f20c36fc733a68d13145a4a5a2d69c7398acf Mon Sep 17 00:00:00 2001 From: Jason DeBacker Date: Thu, 11 Dec 2025 11:29:02 -0500 Subject: [PATCH 08/13] run dynamic --- taxbrain/tests/test_brain.py | 3 +++ taxbrain/tests/test_utils.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/taxbrain/tests/test_brain.py b/taxbrain/tests/test_brain.py index 46c8fd0..dd5235f 100644 --- a/taxbrain/tests/test_brain.py +++ b/taxbrain/tests/test_brain.py @@ -139,6 +139,7 @@ def test_stacked_run_corporate(): def test_weighted_totals(tb_static): + tb_static.run() table = tb_static.weighted_totals("combined") assert isinstance(table, pd.DataFrame) # table.to_csv("expected_weighted_table.csv") @@ -165,6 +166,7 @@ def test_weighted_totals(tb_static): def test_multi_var_table(tb_dynamic): + tb_dynamic.run() with pytest.raises(ValueError): tb_dynamic.multi_var_table(["iitax"], "calc") with pytest.raises(TypeError): @@ -176,6 +178,7 @@ def test_multi_var_table(tb_dynamic): def test_differences_table(tb_dynamic): + tb_dynamic.run() table = tb_dynamic.differences_table(2018, "weighted_deciles", "combined") assert isinstance(table, pd.DataFrame) diff --git a/taxbrain/tests/test_utils.py b/taxbrain/tests/test_utils.py index 73e73e4..5c52082 100644 --- a/taxbrain/tests/test_utils.py +++ b/taxbrain/tests/test_utils.py @@ -3,16 +3,19 @@ def test_distribution_plot(tb_static): + tb_static.run() fig = taxbrain.distribution_plot(tb_static, 2019) def test_differences_plot(tb_static): + tb_static.run() fig = taxbrain.differences_plot(tb_static, "combined") with pytest.raises(AssertionError): taxbrain.differences_plot(tb_static, "wages") def test_volcano_plot(tb_static): + tb_static.run() fig = taxbrain.volcano_plot(tb_static, 2019) with pytest.raises(ValueError): taxbrain.volcano_plot(tb_static, 2019, min_y=-10000) @@ -27,10 +30,12 @@ def test_volcano_plot(tb_static): def test_lorenz_curve(tb_static): + tb_static.run() fig = taxbrain.lorenz_curve(tb_static, 2019) def test_revenue_plot(tb_static): + tb_static.run() fig = taxbrain.revenue_plot(tb_static) with pytest.raises(ValueError): taxbrain.revenue_plot(tb_static, tax_vars=["income", "combined"]) From 19cffc15b76e43310e0508432756e0289e8f1c1a Mon Sep 17 00:00:00 2001 From: Jason DeBacker Date: Thu, 11 Dec 2025 11:30:06 -0500 Subject: [PATCH 09/13] format --- cs-config/cs_config/functions.py | 2 +- taxbrain/taxbrain.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cs-config/cs_config/functions.py b/cs-config/cs_config/functions.py index bced702..a9a3018 100644 --- a/cs-config/cs_config/functions.py +++ b/cs-config/cs_config/functions.py @@ -154,7 +154,7 @@ def run_model(meta_params_dict, adjustment): sampling_seed = 180 full_sample = pd.read_csv(input_path) data_start_year = taxcalc.Records.CPSCSV_YEAR - weights = os.path.join(taxcalc.Records.CODE_PATH, 'cps_weights.csv.gz') + weights = os.path.join(taxcalc.Records.CODE_PATH, "cps_weights.csv.gz") else: raise ValueError( f"Data source '{meta_params.data_source}' is not supported." diff --git a/taxbrain/taxbrain.py b/taxbrain/taxbrain.py index 76c432c..d256e81 100644 --- a/taxbrain/taxbrain.py +++ b/taxbrain/taxbrain.py @@ -17,6 +17,7 @@ from paramtools import ValidationError from pathlib import Path + class TaxBrain: FIRST_BUDGET_YEAR = tc.Policy.JSON_START_YEAR @@ -702,7 +703,7 @@ def _make_calculators(self): records = tc.Records.tmd_constructor( data_path=Path(self.TMD_DATA_FILE), weights_path=Path(self.TMD_WEIGHTS_FILE), - growfactors=gf_base + growfactors=gf_base, ) elif isinstance(self.microdata, dict): if self.microdata["growfactors"] is None: @@ -759,7 +760,7 @@ def _make_calculators(self): records = tc.Records.tmd_constructor( data_path=Path(self.TMD_DATA_FILE), weights_path=Path(self.TMD_WEIGHTS_FILE), - growfactors=gf_reform + growfactors=gf_reform, ) elif isinstance(self.microdata, dict): if self.microdata["growfactors"] is None: @@ -833,7 +834,7 @@ def _make_stacked_objects(self): records = tc.Records.tmd_constructor( data_path=Path(self.TMD_DATA_FILE), weights_path=Path(self.TMD_WEIGHTS_FILE), - growfactors=gf_base + growfactors=gf_base, ) elif isinstance(self.microdata, dict): if self.microdata["growfactors"] is None: @@ -892,7 +893,7 @@ def _make_stacked_objects(self): reform_records = tc.Records.tmd_constructor( data_path=Path(self.TMD_DATA_FILE), weights_path=Path(self.TMD_WEIGHTS_FILE), - growfactors=gf_reform + growfactors=gf_reform, ) elif isinstance(self.microdata, dict): if self.microdata["growfactors"] is None: From 12eaab3d1c3900750ecae5de4526cf128398170c Mon Sep 17 00:00:00 2001 From: Jason DeBacker Date: Thu, 11 Dec 2025 15:09:18 -0500 Subject: [PATCH 10/13] fix to filenames for pandoc --- cs-config/cs_config/helpers.py | 2 +- taxbrain/report.py | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/cs-config/cs_config/helpers.py b/cs-config/cs_config/helpers.py index 2be8769..d22a18b 100644 --- a/cs-config/cs_config/helpers.py +++ b/cs-config/cs_config/helpers.py @@ -306,7 +306,7 @@ def arbitrary_defaultdict(): ) # format table for col in tbl.columns: - tbl.update(tbl[col].apply("${:,.2f}".format)) + tbl[col] = tbl[col].apply("${:,.2f}".format) title = RESULTS_TABLE_TITLES[id] tags = RESULTS_TABLE_TAGS[id] diff --git a/taxbrain/report.py b/taxbrain/report.py index 70ca961..6dc06f1 100644 --- a/taxbrain/report.py +++ b/taxbrain/report.py @@ -92,13 +92,9 @@ def format_table(df, int_cols, float_cols, float_perc=2): table of output """ for col in int_cols: - df.update(df[col].astype(int).apply("{:,}".format)) + df[col] = df[col].astype(int).apply("{:,}".format) for col in float_cols: - df.update( - df[col] - .astype(float) - .apply("{:,.{}}".format, args=(float_perc,)) - ) + df[col] = df[col].astype(float).apply("{:,.{}}".format, args=(float_perc,)) return df def export_plot(plot, graph): @@ -124,14 +120,14 @@ def export_plot(plot, graph): full_filename = Path(output_path, filename) plot.savefig(full_filename, dpi=1200, bbox_inches="tight") - return str(full_filename) + return filename if not tb.has_run: tb.run() if not name: name = f"Policy Report-{date()}" if not outdir: - outdir = name.replace(" ", "_") + outdir = name.replace(" ", "-").replace(",", "") if author: author = f"Report Prepared by {author.title()}" # create directory to hold report contents @@ -306,7 +302,7 @@ def export_plot(plot, graph): report_md = write_text(template_path, **text_args) # write PDF, markdown files - filename = name.replace(" ", "-") + filename = name.replace(" ", "-").replace(",", "") pdf_path = Path(output_path, f"{filename}.pdf") md_path = Path(output_path, f"{filename}.md") md_path.write_text(report_md) From 111bfee7d03301890c2470a76a3f8124dad115e1 Mon Sep 17 00:00:00 2001 From: Jason DeBacker Date: Thu, 11 Dec 2025 15:44:06 -0500 Subject: [PATCH 11/13] change expected value for new test --- taxbrain/tests/test_corporate_incidence.py | 32 +++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/taxbrain/tests/test_corporate_incidence.py b/taxbrain/tests/test_corporate_incidence.py index 3c13119..9eba07f 100644 --- a/taxbrain/tests/test_corporate_incidence.py +++ b/taxbrain/tests/test_corporate_incidence.py @@ -307,22 +307,22 @@ def test_validation(): # expected shares if full burden on shareholders: expected = pd.DataFrame( data=[ - 0.000031, - 0.0, - 0.001008, - 0.003991, - 0.003974, - 0.008655, - 0.013243, - 0.020796, - 0.027376, - 0.052368, - 0.077858, - 0.790699, - 1, - 0.074559, - 0.122593, - 0.593546, + 3.12755650e-05, + 0.00000000e+00, + 9.41971262e-04, + 3.66821040e-03, + 3.90232598e-03, + 8.00940431e-03, + 1.28149782e-02, + 2.03518571e-02, + 2.64449904e-02, + 5.06202883e-02, + 7.93136449e-02, + 7.93901054e-01, + 1.00000000e+00, + 7.38510850e-02, + 1.25578069e-01, + 5.94471900e-01, ], index=[ "0-10n", From 2882aec2b5be69e1668866a4b3d20f2dbd6ef966 Mon Sep 17 00:00:00 2001 From: Jason DeBacker Date: Thu, 11 Dec 2025 15:44:15 -0500 Subject: [PATCH 12/13] fix future warning --- taxbrain/report.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/taxbrain/report.py b/taxbrain/report.py index 6dc06f1..d74ff29 100644 --- a/taxbrain/report.py +++ b/taxbrain/report.py @@ -185,9 +185,10 @@ def export_plot(plot, graph): # create differences table if verbose: print("Creating differences table") - diff_table = tb.differences_table( - tb.start_year, "standard_income_bins", "combined" - ).fillna(0) + with pd.option_context('future.no_silent_downcasting', True): + diff_table = tb.differences_table( + tb.start_year, "standard_income_bins", "combined" + ).fillna(0) diff_table.index = DIFF_TABLE_ROW_NAMES decile_diff_table = tb.differences_table( From 75792c2567c1690c906e12654e650a190c10f12f Mon Sep 17 00:00:00 2001 From: Jason DeBacker Date: Thu, 11 Dec 2025 15:44:35 -0500 Subject: [PATCH 13/13] format --- taxbrain/report.py | 8 ++++++-- taxbrain/tests/test_corporate_incidence.py | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/taxbrain/report.py b/taxbrain/report.py index d74ff29..e5113e6 100644 --- a/taxbrain/report.py +++ b/taxbrain/report.py @@ -94,7 +94,11 @@ def format_table(df, int_cols, float_cols, float_perc=2): for col in int_cols: df[col] = df[col].astype(int).apply("{:,}".format) for col in float_cols: - df[col] = df[col].astype(float).apply("{:,.{}}".format, args=(float_perc,)) + df[col] = ( + df[col] + .astype(float) + .apply("{:,.{}}".format, args=(float_perc,)) + ) return df def export_plot(plot, graph): @@ -185,7 +189,7 @@ def export_plot(plot, graph): # create differences table if verbose: print("Creating differences table") - with pd.option_context('future.no_silent_downcasting', True): + with pd.option_context("future.no_silent_downcasting", True): diff_table = tb.differences_table( tb.start_year, "standard_income_bins", "combined" ).fillna(0) diff --git a/taxbrain/tests/test_corporate_incidence.py b/taxbrain/tests/test_corporate_incidence.py index 9eba07f..9723bee 100644 --- a/taxbrain/tests/test_corporate_incidence.py +++ b/taxbrain/tests/test_corporate_incidence.py @@ -308,7 +308,7 @@ def test_validation(): expected = pd.DataFrame( data=[ 3.12755650e-05, - 0.00000000e+00, + 0.00000000e00, 9.41971262e-04, 3.66821040e-03, 3.90232598e-03, @@ -319,7 +319,7 @@ def test_validation(): 5.06202883e-02, 7.93136449e-02, 7.93901054e-01, - 1.00000000e+00, + 1.00000000e00, 7.38510850e-02, 1.25578069e-01, 5.94471900e-01,