Skip to content

Commit

Permalink
Exclude docs/guide directory tree from cstest in Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholmer committed Jan 4, 2025
1 parent cf704ef commit 9fb604c
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 64 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ tctest-jit:
TOPLEVEL_JSON_FILES := $(shell ls -l ./*json | awk '{print $$9}')
TAXCALC_JSON_FILES := $(shell ls -l ./taxcalc/*json | awk '{print $$9}')
TESTS_JSON_FILES := $(shell ls -l ./taxcalc/tests/*json | awk '{print $$9}')
PYLINT_OPTS1 = --disable=locally-disabled --score=no --jobs=4
PYLINT_OPTS2 = --disable=R0801,R0401
PYLINT_OPTIONS = $(PYLINT_OPTS1) $(PYLINT_OPTS2)
PYLINT_DISABLE = locally-disabled,duplicate-code,cyclic-import
PYLINT_OPTIONS = --disable=$(PYLINT_DISABLE) --score=no --jobs=4
EXCLUDED_PATHS = taxcalc/validation,docs/guide

.PHONY=cstest
cstest:
@-pycodestyle --exclude=taxcalc/validation/taxsim35/*py .
@-pycodestyle --exclude=$(EXCLUDED_PATHS) .
@-pycodestyle --ignore=E501,E121 $(TOPLEVEL_JSON_FILES)
@-pycodestyle --ignore=E501,E121 $(TAXCALC_JSON_FILES)
@-pycodestyle --ignore=E501,E121 $(TESTS_JSON_FILES)
@-pylint $(PYLINT_OPTIONS) --ignore-paths=taxcalc/validation/.* .
@-pylint $(PYLINT_OPTIONS) --ignore-paths=$(EXCLUDED_PATHS) .

define coverage-cleanup
rm -f .coverage htmlcov/*
Expand Down
9 changes: 3 additions & 6 deletions docs/guide/make/make_io_vars.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"""
Helper functions used in make_uguide.py module.
"""
import taxcalc as tc
import pandas as pd
import numpy as np
import taxcalc as tc


def make_io_vars(path, iotype):
Expand Down Expand Up @@ -37,7 +34,7 @@ def form_one(row):
txt = '_IRS Form Location:_ \n'
formdict = row.form
for yrange in sorted(formdict.keys()):
txt += f'{yrange}: {formdict[yrange]} \n'
txt += '{}: {} \n'.format(yrange, formdict[yrange])
return txt

def form(df):
Expand Down Expand Up @@ -69,7 +66,7 @@ def create_io_df(path, iotype):
DataFrame including input and output variables.
"""
# Read json file and convert to a dict.
with open(path, 'r', encoding='utf-8') as vfile:
with open(path) as vfile:
json_text = vfile.read()
variables = tc.json_to_dict(json_text)
assert isinstance(variables, dict)
Expand Down
21 changes: 7 additions & 14 deletions docs/guide/make/make_params.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"""
Helper functions used in make_uguide.py module.
"""
import os
import numpy as np
import pandas as pd
from collections import OrderedDict
import taxcalc as tc
import os


CURDIR_PATH = os.path.abspath(os.path.dirname(__file__))
Expand All @@ -16,7 +14,7 @@
END_YEAR_SHORT = 2020
END_YEAR_LONG = 2027

# Order for policy_params.md
# Order for policy_params.md.
SECTION_1_ORDER = ['Parameter Indexing',
'Payroll Taxes',
'Social Security Taxability',
Expand All @@ -37,8 +35,7 @@


def make_params(path, ptype):
"""
Make string with all parameter information.
""" Make string with all parameter information.
Args:
path: Path to parameter file.
Expand All @@ -47,7 +44,7 @@ def make_params(path, ptype):
Returns:
Single string with all parameter information.
"""
with open(path, 'r', encoding='utf-8') as pfile:
with open(path) as pfile:
json_text = pfile.read()
params = tc.json_to_dict(json_text)
df = pd.DataFrame(params).transpose().drop('schema')
Expand Down Expand Up @@ -86,8 +83,7 @@ def make_params(path, ptype):


def boolstr(b):
"""
Return a bool value or Series as 'True'/'False' strings.
""" Return a bool value or Series as 'True'/'False' strings.
Args:
b: Bool value or pandas Series.
Expand All @@ -105,15 +101,12 @@ def boolstr(b):


def paramtextdf(df, ptype):
"""
Don't include sections - do that later.
""" Don't include sections - do that later.
Args:
df: DataFrame representing parameters.
ptype:
"""
# pylint: disable=too-many-locals

def title(df):
return '#### `' + df.index + '` \n'

Expand Down
27 changes: 12 additions & 15 deletions docs/guide/make/make_uguide.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

import os
import sys
# pylint: disable=import-error
from make_params import make_params
from make_io_vars import make_io_vars
# Other scripts in this folder.
import make_params
import make_io_vars

CURDIR_PATH = os.path.abspath(os.path.dirname(__file__))

Expand All @@ -33,30 +33,27 @@


def main():
"""
High-level logic.
"""
# Policy parameters.
policy_param_text = make_params(POLICY_PATH, 'policy')
policy_param_text = make_params.make_params(POLICY_PATH, 'policy')
write_file(policy_param_text, 'policy_params')
# Assumption parameters, created separately for growdiff and consumption.
growdiff_param_text = make_params(GROWDIFF_PATH, 'growdiff')
consumption_param_text = make_params(CONSUMPTION_PATH, 'consumption')
growdiff_param_text = make_params.make_params(GROWDIFF_PATH, 'growdiff')
consumption_param_text = make_params.make_params(CONSUMPTION_PATH,
'consumption')
assumption_param_text = ('## Growdiff\n\n' + growdiff_param_text +
'\n\n## Consumption\n\n' + consumption_param_text)
write_file(assumption_param_text, 'assumption_params')
# Input and output variables.
input_var_text = make_io_vars(IOVARS_PATH, 'read')
input_var_text = make_io_vars.make_io_vars(IOVARS_PATH, 'read')
write_file(input_var_text, 'input_vars')
output_var_text = make_io_vars(IOVARS_PATH, 'calc')
output_var_text = make_io_vars.make_io_vars(IOVARS_PATH, 'calc')
write_file(output_var_text, 'output_vars')
# Normal return code
return 0


def write_file(text, file):
"""
Writes the concatenation of a template and calculated text to a file.
""" Writes the concatenation of a template and calculated text to a file.
Args:
text: String with calculated documentation.
Expand All @@ -68,9 +65,9 @@ def write_file(text, file):
"""
template = os.path.join(TEMPLATE_PATH, file + '_template.md')
outfile = os.path.join(OUTPUT_PATH, file + '.md')
with open(template, 'r', encoding='utf-8') as f:
with open(template, 'r') as f:
template_text = f.read()
with open(outfile, 'w', encoding='utf-8') as f:
with open(outfile, 'w') as f:
f.write(template_text + '\n\n' + text)


Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
with open("README.md") as f:
longdesc = f.read()

version = "4.4.0"
VERSION = "4.4.0"

config = {
"description": "Tax Calculator",
Expand All @@ -12,7 +12,7 @@
"description": "taxcalc",
"long_description_content_type": "text/markdown",
"long_description": longdesc,
"version": version,
"version": VERSION,
"license": "CC0 1.0 Universal (CC0 1.0) Public Domain Dedication",
"packages": ["taxcalc", "taxcalc.cli"],
"include_package_data": True,
Expand Down
43 changes: 21 additions & 22 deletions taxcalc/tests/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,21 @@ def test_make_apply_function():


@apply_jit(["a", "b"], ["x", "y", "z"], nopython=True)
def Magic_calc(x, y, z):
def magic_calc(x, y, z):
a = x + y
b = x + y + z
return (a, b)


def Magic(pm, pf):
def magic(pm, pf):
# Adjustments
outputs = pf.a, pf.b = Magic_calc(pm, pf)
outputs = pf.a, pf.b = magic_calc(pm, pf)
header = ['a', 'b']
return DataFrame(data=np.column_stack(outputs), columns=header)


@iterate_jit(nopython=True)
def Magic_calc2(x, y, z):
def magic_calc2(x, y, z):
a = x + y
b = x + y + z
return (a, b)
Expand All @@ -119,8 +119,8 @@ class Foo:


@iterate_jit(nopython=True)
def faux_function(MARS):
if MARS == 1:
def faux_function(mars):
if mars == 1:
var = 2
else:
var = 1
Expand All @@ -134,8 +134,7 @@ def ret_everything(a, b, c, d, e, f):
d = a + b
e = a + b
f = a + b
return (c, d, e,
f)
return (c, d, e, f)


def test_magic_apply_jit():
Expand All @@ -146,7 +145,7 @@ def test_magic_apply_jit():
pf.x = np.ones((5,))
pf.y = np.ones((5,))
pf.z = np.ones((5,))
xx = Magic(pm, pf)
xx = magic(pm, pf)
exp = DataFrame(data=[[2.0, 3.0]] * 5, columns=["a", "b"])
assert_frame_equal(xx, exp)

Expand All @@ -159,7 +158,7 @@ def test_magic_apply_jit_swap():
pf.x = np.ones((5,))
pf.y = np.ones((5,))
pf.z = np.ones((5,))
xx = Magic(pf, pm)
xx = magic(pf, pm)
exp = DataFrame(data=[[2.0, 3.0]] * 5, columns=["a", "b"])
assert_frame_equal(xx, exp)

Expand All @@ -172,15 +171,15 @@ def test_magic_iterate_jit():
pf.x = np.ones((5,))
pf.y = np.ones((5,))
pf.z = np.ones((5,))
xx = Magic_calc2(pm, pf)
xx = magic_calc2(pm, pf)
exp = DataFrame(data=[[2.0, 3.0]] * 5, columns=["a", "b"])
assert_frame_equal(xx, exp)


def test_faux_function_iterate_jit():
pm = Foo()
pf = Foo()
pf.MARS = np.ones((5,))
pf.mars = np.ones((5,))
pf.var = np.ones((5,))
ans = faux_function(pm, pf)
exp = DataFrame(data=[2.0] * 5, columns=['var'])
Expand All @@ -203,7 +202,7 @@ def test_ret_everything_iterate_jit():


@iterate_jit(nopython=True)
def Magic_calc3(x, y, z):
def magic_calc3(x, y, z):
a = x + y
b = a + z
return (a, b)
Expand All @@ -217,14 +216,14 @@ def test_function_takes_kwarg():
pf.x = np.ones((5,))
pf.y = np.ones((5,))
pf.z = np.ones((5,))
ans = Magic_calc3(pm, pf)
ans = magic_calc3(pm, pf)
exp = DataFrame(data=[[2.0, 3.0]] * 5,
columns=["a", "b"])
assert_frame_equal(ans, exp)


@iterate_jit(nopython=True)
def Magic_calc4(x, y, z):
def magic_calc4(x, y, z):
a = x + y
b = a + z
return (a, b)
Expand All @@ -238,14 +237,14 @@ def test_function_no_parameters_listed():
pf.x = np.ones((5,))
pf.y = np.ones((5,))
pf.z = np.ones((5,))
ans = Magic_calc4(pm, pf)
ans = magic_calc4(pm, pf)
exp = DataFrame(data=[[2.0, 3.0]] * 5,
columns=["a", "b"])
assert_frame_equal(ans, exp)


@iterate_jit(parameters=['w'], nopython=True)
def Magic_calc5(w, x, y, z):
def magic_calc5(w, x, y, z):
a = x + y
b = w[0] + x + y + z
return (a, b)
Expand All @@ -260,7 +259,7 @@ def test_function_parameters_optional():
pf.x = np.ones((5,))
pf.y = np.ones((5,))
pf.z = np.ones((5,))
ans = Magic_calc5(pm, pf)
ans = magic_calc5(pm, pf)
exp = DataFrame(data=[[2.0, 4.0]] * 5,
columns=["a", "b"])
assert_frame_equal(ans, exp)
Expand Down Expand Up @@ -298,7 +297,7 @@ def test_iterate_jit_raises_on_unknown_return_argument():
ans = uf2(pm, pf)


def Magic_calc6(w, x, y, z):
def magic_calc6(w, x, y, z):
a = x + y
b = w[0] + x + y + z
return (a, b)
Expand All @@ -313,8 +312,8 @@ def test_force_no_jit():
os.environ['NOTAXCALCJIT'] = 'NOJIT'
# reload the decorators module
importlib.reload(taxcalc.decorators)
# verify Magic_calc6 function works as expected
Magic_calc6_ = iterate_jit(parameters=['w'], nopython=True)(Magic_calc6)
# verify magic_calc6 function works as expected
magic_calc6_ = iterate_jit(parameters=['w'], nopython=True)(magic_calc6)
pm = Foo()
pf = Foo()
pm.a = np.ones((1, 5))
Expand All @@ -323,7 +322,7 @@ def test_force_no_jit():
pf.x = np.ones((5,))
pf.y = np.ones((5,))
pf.z = np.ones((5,))
ans = Magic_calc6_(pm, pf)
ans = magic_calc6_(pm, pf)
exp = DataFrame(data=[[2.0, 4.0]] * 5,
columns=["a", "b"])
assert_frame_equal(ans, exp)
Expand Down

0 comments on commit 9fb604c

Please sign in to comment.