Skip to content

Commit

Permalink
Make CLI dump output contain high-precision weights when using TMD in…
Browse files Browse the repository at this point in the history
…put data
  • Loading branch information
martinholmer committed Oct 27, 2024
1 parent eaffd02 commit 9518205
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion taxcalc/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def _read_weights(self, weights):
msg = 'weights is not None or a string or a Pandas DataFrame'
raise ValueError(msg)
assert isinstance(WT, pd.DataFrame)
setattr(self, 'WT', WT.astype(np.float32))
setattr(self, 'WT', WT.astype(np.float64))
del WT

def _extrapolate(self, year):
Expand Down
17 changes: 13 additions & 4 deletions taxcalc/taxcalcio.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,17 @@ def write_output_file(self, output_dump, dump_varset,
outdf = self.minimal_output()
column_order = outdf.columns
assert len(outdf.index) == self.calc.array_len
outdf.to_csv(self._output_filename, columns=column_order,
index=False, float_format='%.2f')
if self.tmd_input_data:
if "s006" in outdf:
weights = outdf["s006"].round(5)
outdf = outdf.round(2)
if "s006" in outdf:
outdf["s006"] = weights
outdf.to_csv(self._output_filename, columns=column_order,

Check warning on line 559 in taxcalc/taxcalcio.py

View check run for this annotation

Codecov / codecov/patch

taxcalc/taxcalcio.py#L554-L559

Added lines #L554 - L559 were not covered by tests
index=False)
else:
outdf.to_csv(self._output_filename, columns=column_order,
index=False, float_format='%.2f')
del outdf
gc.collect()

Expand Down Expand Up @@ -788,8 +797,8 @@ def dump_output(self, calcx, dump_varset, mtr_inctax, mtr_paytax):
vardata = calcx.array(varname)
if varname in recs_vinfo.INTEGER_VARS:
odf[varname] = vardata
else:
odf[varname] = vardata.round(2) # rounded to nearest cent
else: # specify precision that can handle small TMD area weights
odf[varname] = vardata.round(5)
odf = odf.copy()
# specify mtr values in percentage terms
if 'mtr_inctax' in varset:
Expand Down
2 changes: 1 addition & 1 deletion taxcalc/tests/benefits_expect.csv
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ year,bname,benamt,bencnt,benavg
2031,snap,158.784,81.873,1.9
2031,wic,5.313,23.047,0.2
2031,tanf,36.49,9.639,3.8
2031,vet,247.79,12.699,19.5
2031,vet,247.791,12.699,19.5
2031,housing,83.299,14.327,5.8
2032,ssi,79.862,17.902,4.5
2032,mcare,1553.523,95.617,16.2
Expand Down
2 changes: 1 addition & 1 deletion taxcalc/tests/puf_var_wght_means_by_year.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ c00100,Federal AGI, 50840, 54457, 54942, 55071, 58024, 60318, 6159
c02500,OASDI benefits in AGI, 1295, 1394, 1416, 1479, 1501, 1587, 1690, 1832, 2005, 2129, 2428, 2659, 2844, 3028, 3214, 3413, 3619, 3833, 4055, 4308, 4459, 4698
c04470,Post-phase-out itemized deduction, 5908, 6037, 6150, 6383, 6563, 6803, 7011, 7493, 7881, 8018, 8324, 8672, 8950, 9288, 9614, 9940, 10266, 10611, 10970, 11450, 11641, 12004
c04600,Post-phase-out personal exemption, 7105, 7131, 7163, 7217, 7149, 7247, 7380, 7471, 7481, 7806, 8373, 8834, 9054, 9248, 9434, 9612, 9797, 9988, 10186, 10398, 10579, 10791
c04800,Federal regular taxable income, 35753, 39297, 39663, 39591, 42568, 44523, 45416, 46475, 55959, 54603, 57321, 58385, 60072, 61575, 63147, 64911, 66831, 68828, 70916, 73686, 74835, 76970
c04800,Federal regular taxable income, 35753, 39297, 39663, 39591, 42568, 44523, 45416, 46476, 55959, 54603, 57321, 58385, 60072, 61575, 63147, 64911, 66831, 68828, 70916, 73686, 74835, 76970
c05200,Regular tax on taxable income, 7671, 8731, 8725, 8584, 9499, 10001, 10138, 10475, 13361, 12576, 13165, 13230, 13561, 13847, 14165, 14544, 14965, 15398, 15840, 16404, 16816, 17278
c07180,Child care credit, 17, 17, 17, 17, 17, 17, 17, 17, 0, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 16, 16
c07220,Child tax credit (adjusted), 158, 155, 147, 143, 139, 134, 129, 124, 359, 116, 107, 101, 97, 94, 91, 88, 85, 82, 80, 77, 74, 72
Expand Down

0 comments on commit 9518205

Please sign in to comment.