Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate pycodestyle warnings #2858

Merged
merged 4 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ 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_FILES := $(shell grep -rl --include="*py" disable=locally-disabled .)
PYLINT_OPTIONS = --disable=locally-disabled --score=no --jobs=4
PYLINT_OPTIONS = --disable=locally-disabled --score=no --jobs=4 --disable=R0801
RECIPE_FILES := $(shell ls -l ./docs/recipes/recipe*.ipynb | awk '{print $$9}')
PYLINT_IGNORE = C0103,C0111,E0401,E1120,R0913,R0914,W0401,W0614
RECIPE_OPTIONS = --disable=$(PYLINT_IGNORE) --score=no --jobs=4
RECIPE_IGNORE = C0103,C0111,E0401,E1120,R0913,R0914,W0401,W0614,R0801
RECIPE_OPTIONS = --disable=$(RECIPE_IGNORE) --score=no --jobs=4

.PHONY=cstest
cstest:
-pycodestyle .
-pycodestyle . | grep -v taxcalc/validation
@-pycodestyle --ignore=E501,E121 $(TOPLEVEL_JSON_FILES)
@-pycodestyle --ignore=E501,E121 $(TAXCALC_JSON_FILES)
@-pycodestyle --ignore=E501,E121 $(TESTS_JSON_FILES)
Expand Down
6 changes: 3 additions & 3 deletions docs/guide/make/make_io_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@


def make_io_vars(path, iotype):
""" Create string of information for input or output variables.
"""
Create string of information for input or output variables.

Args:
path: Path to records_variables.json.
Expand All @@ -18,8 +19,7 @@ def title(df):
return '## `' + df.index + '` \n'

def required(df):
return np.where(df.required == True, '**_Required Input Variable_** \n',
'')
return np.where(df.required, '**_Required Input Variable_** \n', '')

def description(df):
return '_Description_: ' + df.desc + ' \n'
Expand Down
59 changes: 34 additions & 25 deletions docs/guide/make/make_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,27 @@ def make_params(path, ptype):
df['content'] = paramtextdf(df, ptype)
# Only policy parameters have sections.
if ptype == 'policy':
df.section_1 = np.where(df.section_1 == '',
'Other Parameters (not in Tax-Brain webapp)', df.section_1)
df.section_1 = np.where(
df.section_1 == '',
'Other Parameters (not in Tax-Brain webapp)',
df.section_1
)
section_1_order_index = dict(zip(SECTION_1_ORDER,
range(len(SECTION_1_ORDER))))
range(len(SECTION_1_ORDER))))
df['section_1_order'] = df.section_1.map(section_1_order_index)
df.sort_values(['section_1_order', 'section_2'], inplace=True)
# Add section titles when they change.
df['new_section_1'] = ~df.section_1.eq(df.section_1.shift())
df['new_section_2'] = (~df.section_2.eq(df.section_2.shift()) &
(df.section_2 > ''))
df['section_1_content'] = np.where(df.new_section_1,
'## ' + df.section_1 + '\n\n', '')
df['section_2_content'] = np.where(df.new_section_2,
'### ' + df.section_2 + '\n\n', '')
df['new_section_2'] = (
~df.section_2.eq(df.section_2.shift()) &
(df.section_2 > '')
)
df['section_1_content'] = np.where(
df.new_section_1, '## ' + df.section_1 + '\n\n', ''
)
df['section_2_content'] = np.where(
df.new_section_2, '### ' + df.section_2 + '\n\n', ''
)
# Concatenate section titles with content for each parameter.
df.content = df.section_1_content + df.section_2_content + df.content
# Return a single string.
Expand All @@ -95,41 +102,41 @@ def boolstr(b):

def paramtextdf(df, ptype):
""" Don't include sections - do that later.

Args:
df: DataFrame representing parameters.
ptype:
ptype:
"""
def title(df):
return '#### `' + df.index + '` \n'

def long_name(df):
return '_Long Name:_ ' + df.title + ' \n'

def description(df):
return '_Description:_ ' + df.description + ' \n'

def notes(df):
return np.where(df.notes == '', '', '_Notes:_ ' + df.notes + ' \n')

def effect_puf_cps_one(row):
return ('_Has An Effect When Using:_' +
' _PUF data:_ ' + boolstr(row.compatible_data['puf']) +
' _CPS data:_ ' + boolstr(row.compatible_data['cps']) + ' \n')

def effect_puf_cps(df):
return df.apply(effect_puf_cps_one, axis=1)

def inflation_indexed(df):
return ('_Can Be Inflation Indexed:_ ' + boolstr(df.indexable) +
' _Is Inflation Indexed:_ ' + boolstr(df.indexed) + ' \n')

def value_type(df):
return '_Value Type:_ ' + df.type + ' \n'

def known_values_one(row):
# Requires non-vectorizable functions.
txt ='_Known Values:_ \n'
txt = '_Known Values:_ \n'
nvalues = len(row['values'][0])
if nvalues == 5:
txt += ' for: [single, mjoint, mseparate, headhh, widow] \n'
Expand All @@ -142,10 +149,10 @@ def known_values_one(row):
val = val[0]
txt += str(cyr) + ': ' + str(val) + ' \n'
return txt

def known_values(df):
return df.apply(known_values_one, axis=1)

def default_value_one(row):
return '_Default Value:_ ' + str(row.value[0]['value']) + ' \n'

Expand All @@ -158,10 +165,10 @@ def valid_range_one(row):
' min = ' + str(r['min']) +
' and max = ' + str(r['max']) + ' \n' +
'_Out-of-Range Action:_ ' + r.get('level', 'error') + ' \n')

def valid_range(df):
return df.apply(valid_range_one, axis=1)

text = title(df)
# Add "long name" for growdiff and consumption parameters.
if ptype != 'policy':
Expand Down Expand Up @@ -214,8 +221,10 @@ def reformat_params():
for idx in range(0, len(params[param])):
if params[param][idx]['year'] == year:
list_vals1.append(params[param][idx]['value'])
if (params[param][idx]['year'] !=
params[param][idx - 1]['year']):
if (
params[param][idx]['year'] !=
params[param][idx - 1]['year']
):
list_vals2.append(list_vals1)
params_dict[param]['values'] = list_vals2
return params_dict
8 changes: 4 additions & 4 deletions docs/guide/make/make_uguide.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
CONSUMPTION_PATH = os.path.join(TAXCALC_PATH, 'consumption.json')
GROWDIFF_PATH = os.path.join(TAXCALC_PATH, 'growdiff.json')
TEMPLATE_PATH = os.path.join(CURDIR_PATH, '../templates')
OUTPUT_PATH = os.path.join(CURDIR_PATH, '..')
OUTPUT_PATH = os.path.join(CURDIR_PATH, '..')

START_YEAR = 2013
END_YEAR_SHORT = 2020
Expand All @@ -39,9 +39,9 @@ def main():
# Assumption parameters, created separately for growdiff and consumption.
growdiff_param_text = make_params.make_params(GROWDIFF_PATH, 'growdiff')
consumption_param_text = make_params.make_params(CONSUMPTION_PATH,
'consumption')
'consumption')
assumption_param_text = ('## Growdiff\n\n' + growdiff_param_text +
'\n\n## Consumption\n\n' + consumption_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.make_io_vars(IOVARS_PATH, 'read')
Expand All @@ -65,7 +65,7 @@ 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') as f:
with open(template, 'r') as f:
template_text = f.read()
with open(outfile, 'w') as f:
f.write(template_text + '\n\n' + text)
Expand Down
5 changes: 3 additions & 2 deletions extend_tcja.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ def main():
ifactor28 = 1.0 + pirates[2028-taxcalc.Policy.JSON_START_YEAR]
# specify extend-TCJA-beyond-2025 reform
# ... get 2025 parameter values
pol.set_year(2025)
year = 2025
pol.set_year(year)
pdata = dict(pol.items())
# ... write reform header comments
print( '// REFORM TO EXTEND TEMPORARY TCJA PROVISIONS BEYOND 2025')
print(f'// REFORM TO EXTEND TEMPORARY TCJA PROVISIONS BEYOND {year}')
print(f'// USING TAX-CALCULATOR {taxcalc.__version__}')
print(f'// WITH 2025-to-2026 INDEXING FACTOR = {ifactor25:.6f}')
print(f'// AND 2028-to-2029 INDEXING FACTOR = {ifactor28:.6f}')
Expand Down
Loading
Loading