Skip to content

Commit

Permalink
Fix NaN values produced by 0.00 agency rates
Browse files Browse the repository at this point in the history
  • Loading branch information
dfsnow committed May 3, 2024
1 parent 1ad97b0 commit 0f1d266
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions R/tax_bill.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-tax_bill.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 0f1d266

Please sign in to comment.