From 0f1d2669f6ec6604197320a27a7cff732c39f745 Mon Sep 17 00:00:00 2001 From: Dan Snow Date: Fri, 3 May 2024 21:06:14 +0000 Subject: [PATCH] Fix NaN values produced by 0.00 agency rates --- R/tax_bill.R | 1 + tests/testthat/test-tax_bill.R | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/R/tax_bill.R b/R/tax_bill.R index 5ebca11..887cd01 100644 --- a/R/tax_bill.R +++ b/R/tax_bill.R @@ -194,6 +194,7 @@ tax_bill <- function(year_vec, # Calculate the exemption effect by subtracting the exempt amount from # the total taxable EAV dt[, agency_tax_rate := agency_total_ext / as.numeric(agency_total_eav)] + dt[, agency_tax_rate := replace(agency_tax_rate, is.nan(agency_tax_rate), 0)] dt[, tax_amt_exe := exe_total * agency_tax_rate] dt[, tax_amt_pre_exe := round(eav * agency_tax_rate, 2)] dt[, tax_amt_post_exe := round(tax_amt_pre_exe - tax_amt_exe, 2)] diff --git a/tests/testthat/test-tax_bill.R b/tests/testthat/test-tax_bill.R index 16250c1..8799219 100644 --- a/tests/testthat/test-tax_bill.R +++ b/tests/testthat/test-tax_bill.R @@ -244,4 +244,10 @@ test_that("agnostic to input data.table row order", { ) }) +test_that("Returns 0 for agency with base/levy of 0", { + expect_false( + any(is.nan(tax_bill(2022, c("12283000140000", "12284120030000"))$final_tax)) + ) +}) + DBI::dbDisconnect(ptaxsim_db_conn)