Skip to content

Commit

Permalink
Merge pull request PSLmodels#2058 from martinholmer/develop-with-pyth…
Browse files Browse the repository at this point in the history
…on36

Switch Tax-Calculator code to being compatible with Python 3.6 only
  • Loading branch information
martinholmer authored Sep 11, 2018
2 parents 1d9db6f + ba55a28 commit 8802bfd
Show file tree
Hide file tree
Showing 66 changed files with 1,621 additions and 1,808 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ sudo: false
language: python
python:
- "3.6"
- "2.7"

install:
# Install conda
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,18 @@ tctest: package
TAXCALC_JSON_FILES := $(shell ls -l ./taxcalc/*json | awk '{print $$9}')
TESTS_JSON_FILES := $(shell ls -l ./taxcalc/tests/*json | awk '{print $$9}')
PYLINT_FILES := $(shell grep -rl --include="*py" disable=locally-disabled .)
PYLINT_OPTIONS = --disable=locally-disabled --score=no --jobs=4
RECIPE_FILES := $(shell ls -l ./docs/cookbook/recipe*py | awk '{print $$9}')
RECIPE_OPTIONS = --disable=C0103,C0111,W0401,W0614 --score=no --jobs=4

.PHONY=cstest
cstest:
pycodestyle taxcalc
pycodestyle docs/cookbook
@pycodestyle --ignore=E501,E121 $(TAXCALC_JSON_FILES)
@pycodestyle --ignore=E501,E121 $(TESTS_JSON_FILES)
@pylint --disable=locally-disabled --score=no --jobs=4 $(PYLINT_FILES)
@pylint $(PYLINT_OPTIONS) $(PYLINT_FILES)
@pylint $(RECIPE_OPTIONS) $(RECIPE_FILES)

define coverage-cleanup
rm -f .coverage htmlcov/*
Expand Down
11 changes: 5 additions & 6 deletions conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@ build:

requirements:
build:
- python
- python >=3.6.5
- numpy >=1.12.1
- pandas >=0.22.0
- bokeh >=0.12.3
- numba
- toolz
- six
- bokeh >=0.12.3

run:
- python
- python >=3.6.5
- numpy >=1.12.1
- pandas >=0.22.0
- bokeh >=0.12.3
- numba
- toolz
- six
- bokeh >=0.12.3

test:
commands:
Expand Down
1 change: 0 additions & 1 deletion conda.recipe/run_test.py

This file was deleted.

4 changes: 2 additions & 2 deletions docs/cookbook.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ <h1 id="toc">Cookbook of Tested Recipes for Python Programming with
<p>This document tells you how to use Tax-Calculator, an open-source
federal income and payroll tax simulation model, in Python scripts
that you can run on your own computer. Note that these recipes
require Tax-Calculator release 0.20.1 or higher. For other ways of
using Tax-Calculator, see the
require Tax-Calculator release 0.21.0 or higher running on Python 3.6.
For other ways of using Tax-Calculator, see the
<a href="https://open-source-economics.github.io/Tax-Calculator/">
user documentation</a>, which this Cookbook assumes you have read.</p>

Expand Down
8 changes: 3 additions & 5 deletions docs/cookbook/make_cookbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
python make_cookbook.py
"""
# CODING-STYLE CHECKS:
# pycodestyle --ignore=E402 make_cookbook.py
# pycodestyle make_cookbook.py
# pylint --disable=locally-disabled make_cookbook.py

from __future__ import print_function
import os
import glob
import string
import shutil


Expand All @@ -22,7 +20,7 @@ def write_html_file(filename):
"""
with open(filename, 'r') as ifile:
txt = ifile.read()
fname = string.replace(filename, 'ingredients/', '')
fname = filename.replace('ingredients/', '')
html = '<title>{}</title><pre>\n{}</pre>\n'.format(fname, txt)
ofilename = '../{}.html'.format(fname)
with open(ofilename, 'w') as ofile:
Expand All @@ -34,7 +32,7 @@ def write_html_file(filename):

# construct HTML files for each recipe in RECIPES list
for recipe in RECIPES:
recipe_root = string.replace(recipe, '.py', '')
recipe_root = recipe.replace('.py', '')
write_html_file('{}.{}'.format(recipe_root, 'py'))
write_html_file('{}.{}'.format(recipe_root, 'res'))
graph = '{}.graph.html'.format(recipe_root)
Expand Down
1 change: 0 additions & 1 deletion docs/cookbook/recipe00.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function # necessary only if using Python 2.7
from taxcalc import *

# use publicly-available CPS input file including benefits
Expand Down
8 changes: 0 additions & 8 deletions docs/cookbook/recipe00.res
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
You loaded data for 2014.
Tax-Calculator startup automatically extrapolated your data to 2014.
WARNING: Tax-Calculator packages for Python 2.7 will
no longer be provided beginning in 2019
because Pandas is stopping development for 2.7
SOLUTION: upgrade to Python 3.6 now
You loaded data for 2014.
Tax-Calculator startup automatically extrapolated your data to 2014.
WARNING: Tax-Calculator packages for Python 2.7 will
no longer be provided beginning in 2019
because Pandas is stopping development for 2.7
SOLUTION: upgrade to Python 3.6 now

REFORM DOCUMENTATION
Baseline Growth-Difference Assumption Values by Year:
Expand Down
9 changes: 4 additions & 5 deletions docs/cookbook/recipe01.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import print_function # necessary only if using Python 2.7
from urllib.request import urlopen
from taxcalc import *
import urllib as url_lib # Python 3.6 uses "import urllib.request as url_lib"

# read two "old" reform files from Tax-Calculator website
# ("old" means the reform files are defined relative to pre-TCJA policy)
Expand All @@ -11,13 +10,13 @@
'open-source-economics/Tax-Calculator/master/taxcalc/reforms/')

baseline_name = '2017_law.json' # pre-TCJA policy
baseline_text = url_lib.urlopen(BASE_URL + baseline_name).read()
baseline_text = urlopen(BASE_URL + baseline_name).read().decode()
baseline = Calculator.read_json_param_objects(baseline_text, None)

reform1_name = 'TCJA_Senate.json' # TCJA as orginally proposed in Senate
reform1_text = url_lib.urlopen(BASE_URL + reform1_name).read()
reform1_text = urlopen(BASE_URL + reform1_name).read().decode()
reform2_name = 'TCJA_Reconciliation.json' # TCJA as passed by Congress
reform2_text = url_lib.urlopen(BASE_URL + reform2_name).read()
reform2_text = urlopen(BASE_URL + reform2_name).read().decode()

# specify Policy object for static analysis of reform1 relative to pre-TCJA
reform1 = Calculator.read_json_param_objects(reform1_text, None)
Expand Down
8 changes: 0 additions & 8 deletions docs/cookbook/recipe01.res
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
You loaded data for 2014.
Tax-Calculator startup automatically extrapolated your data to 2014.
WARNING: Tax-Calculator packages for Python 2.7 will
no longer be provided beginning in 2019
because Pandas is stopping development for 2.7
SOLUTION: upgrade to Python 3.6 now
You loaded data for 2014.
Tax-Calculator startup automatically extrapolated your data to 2014.
WARNING: Tax-Calculator packages for Python 2.7 will
no longer be provided beginning in 2019
because Pandas is stopping development for 2.7
SOLUTION: upgrade to Python 3.6 now
2018_REFORM1_iitax_rev($B)= 1422.1
2018_REFORM2_iitax_rev($B)= 1267.4

Expand Down
1 change: 0 additions & 1 deletion docs/cookbook/recipe02.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function # necessary only if using Python 2.7
from taxcalc import *

# use publicly-available CPS input file
Expand Down
12 changes: 0 additions & 12 deletions docs/cookbook/recipe02.res
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
You loaded data for 2014.
Tax-Calculator startup automatically extrapolated your data to 2014.
WARNING: Tax-Calculator packages for Python 2.7 will
no longer be provided beginning in 2019
because Pandas is stopping development for 2.7
SOLUTION: upgrade to Python 3.6 now
You loaded data for 2014.
Tax-Calculator startup automatically extrapolated your data to 2014.
WARNING: Tax-Calculator packages for Python 2.7 will
no longer be provided beginning in 2019
because Pandas is stopping development for 2.7
SOLUTION: upgrade to Python 3.6 now
You loaded data for 2014.
Tax-Calculator startup automatically extrapolated your data to 2014.
WARNING: Tax-Calculator packages for Python 2.7 will
no longer be provided beginning in 2019
because Pandas is stopping development for 2.7
SOLUTION: upgrade to Python 3.6 now
2020_CURRENT_LAW_P__itax_rev($B)= 1413.43
2020_REFORM_STATIC__itax_rev($B)= 1410.78
2020_REFORM_DYNAMIC_itax_rev($B)= 1400.52
6 changes: 3 additions & 3 deletions docs/cookbook/recipe03.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function # necessary only if using Python 2.7
from taxcalc import *

# use publicly-available CPS input file
Expand Down Expand Up @@ -28,7 +27,7 @@
tot_recips = 0.
tot_amount = 0.
idx = 0
for gname, grp in gbydf:
for grp_interval, grp in gbydf:
recips = grp[grp['eitc'] > 0]['s006'].sum() * 1e-6
tot_recips += recips
amount = (grp['eitc'] * grp['s006']).sum() * 1e-9
Expand All @@ -37,7 +36,8 @@
avg = amount / recips
else:
avg = np.nan
print(results.format(gname, recips, avg))
glabel = '[{:.8g}, {:.8g})'.format(grp_interval.left, grp_interval.right)
print(results.format(glabel, recips, avg))
idx += 1
avg = tot_amount / tot_recips
print(results.format('ALL', tot_recips, avg))
42 changes: 19 additions & 23 deletions docs/cookbook/recipe03.res
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
You loaded data for 2014.
Tax-Calculator startup automatically extrapolated your data to 2014.
WARNING: Tax-Calculator packages for Python 2.7 will
no longer be provided beginning in 2019
because Pandas is stopping development for 2.7
SOLUTION: upgrade to Python 3.6 now
Filing Units Receiving EITC and Average Positive EITC by AGI Category
AGI Category Num(#M) Avg($K)
[-9e+99, 1.0) 0.049 1.399
[1.0, 5000.0) 1.106 0.516
[5000.0, 10000.0) 2.045 1.368
[10000.0, 15000.0) 3.316 1.864
[15000.0, 20000.0) 2.766 3.330
[20000.0, 25000.0) 2.357 4.104
[25000.0, 30000.0) 2.023 3.845
[30000.0, 40000.0) 3.856 2.548
[40000.0, 50000.0) 2.220 1.321
[50000.0, 75000.0) 0.437 0.571
[75000.0, 100000.0) 0.000 nan
[100000.0, 200000.0) 0.000 nan
[200000.0, 500000.0) 0.000 nan
[500000.0, 1000000.0) 0.000 nan
[1000000.0, 1500000.0) 0.000 nan
[1500000.0, 2000000.0) 0.000 nan
[2000000.0, 5000000.0) 0.000 nan
[5000000.0, 10000000.0) 0.000 nan
[10000000.0, 9e+99) 0.000 nan
[-9e+99, 1) 0.049 1.399
[1, 5000) 1.106 0.516
[5000, 10000) 2.045 1.368
[10000, 15000) 3.316 1.864
[15000, 20000) 2.766 3.330
[20000, 25000) 2.357 4.104
[25000, 30000) 2.023 3.845
[30000, 40000) 3.856 2.548
[40000, 50000) 2.220 1.321
[50000, 75000) 0.437 0.571
[75000, 100000) 0.000 nan
[100000, 200000) 0.000 nan
[200000, 500000) 0.000 nan
[500000, 1000000) 0.000 nan
[1000000, 1500000) 0.000 nan
[1500000, 2000000) 0.000 nan
[2000000, 5000000) 0.000 nan
[5000000, 10000000) 0.000 nan
[10000000, 9e+99) 0.000 nan
ALL 20.175 2.443
6 changes: 3 additions & 3 deletions docs/cookbook/recipe04.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function # necessary only if using Python 2.7
from taxcalc import *

# use publicly-available CPS input file
Expand Down Expand Up @@ -61,7 +60,7 @@
tot_response = 0.
tot_baseline = 0.
idx = 0
for gname, grp in gbydf:
for grp_interval, grp in gbydf:
funits = grp['s006'].sum() * 1e-6
tot_funits += funits
response = quantity_response(grp['e19800'],
Expand All @@ -76,7 +75,8 @@
grp_baseline = (grp['e19800'] * grp['s006']).sum() * 1e-9
tot_baseline += grp_baseline
pct_response = 100. * grp_response / grp_baseline
print(results.format(gname, funits, grp_response, pct_response))
glabel = '[{:.8g}, {:.8g})'.format(grp_interval.left, grp_interval.right)
print(results.format(glabel, funits, grp_response, pct_response))
idx += 1
pct_response = 100. * tot_response / tot_baseline
print(results.format('ALL', tot_funits, tot_response, pct_response))
12 changes: 2 additions & 10 deletions docs/cookbook/recipe04.res
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
You loaded data for 2014.
Tax-Calculator startup automatically extrapolated your data to 2014.
WARNING: Tax-Calculator packages for Python 2.7 will
no longer be provided beginning in 2019
because Pandas is stopping development for 2.7
SOLUTION: upgrade to Python 3.6 now
You loaded data for 2014.
Tax-Calculator startup automatically extrapolated your data to 2014.
WARNING: Tax-Calculator packages for Python 2.7 will
no longer be provided beginning in 2019
because Pandas is stopping development for 2.7
SOLUTION: upgrade to Python 3.6 now

Response in Charitable Giving by Earnings Group
Earnings Group Num(#M) Resp($B) Resp(%)
[-9e+99, 50000.0) 110.061 0.703 0.56
[50000.0, 9e+99) 57.451 3.600 2.18
[-9e+99, 50000) 110.061 0.703 0.56
[50000, 9e+99) 57.451 3.600 2.18
ALL 167.512 4.304 1.48
18 changes: 8 additions & 10 deletions docs/cookbook/test_recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
the script output with the expected output in the recipeNN.res file.
"""
# CODING-STYLE CHECKS:
# pycodestyle --ignore=E402 test_recipes.py
# pycodestyle test_recipes.py
# pylint --disable=locally-disabled test_recipes.py

from __future__ import print_function
from datetime import datetime
import os
import glob
import string
import subprocess
import difflib

Expand All @@ -23,28 +21,28 @@

# execute each recipe in RECIPES list and compare output with expected output
for recipe in RECIPES:
out_filename = string.replace(recipe, '.py', '.out')
out_filename = recipe.replace('.py', '.out')
if os.path.isfile(out_filename):
os.remove(out_filename)
try:
out = subprocess.check_output(['python', recipe])
out = subprocess.check_output(['python', recipe]).decode()
except subprocess.CalledProcessError as err:
print('{} FAIL with error rtncode={}'.format(recipe, err.returncode))
continue # to next recipe
with open(string.replace(recipe, '.py', '.res'), 'r') as resfile:
with open(recipe.replace('.py', '.res'), 'r') as resfile:
exp = resfile.read()
# check for differences between out and exp results
actual = out.splitlines(True)
expected = exp.splitlines(True)
expect = exp.splitlines(True)
diff_lines = list()
diff = difflib.unified_diff(expected, actual,
fromfile='expected', tofile='actual', n=0)
diff = difflib.unified_diff(expect, actual,
fromfile='expect', tofile='actual', n=0)
for line in diff:
diff_lines.append(line)
# write actual output to file if any differences; else report PASS
if diff_lines:
print('{} FAIL with output differences'.format(recipe))
outfilename = string.replace(recipe, '.py', '.out')
outfilename = recipe.replace('.py', '.out')
with open(outfilename, 'w') as outfile:
outfile.write(out)
else:
Expand Down
2 changes: 1 addition & 1 deletion docs/make_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
containing information from several JSON files.
"""
# CODING-STYLE CHECKS:
# pycodestyle --ignore=E402 make_index.py
# pycodestyle make_index.py
# pylint --disable=locally-disabled make_index.py

import os
Expand Down
Loading

0 comments on commit 8802bfd

Please sign in to comment.