Skip to content

Commit

Permalink
Fix pylint R0913 and R0917 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholmer committed Jan 3, 2025
1 parent 2253d9b commit 84c2439
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 37 deletions.
1 change: 1 addition & 0 deletions taxcalc/calcfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# pylint: disable=too-many-lines
# pylint: disable=invalid-name
# pylint: disable=too-many-arguments
# pylint: disable=too-many-positional-arguments
# pylint: disable=too-many-locals

import math
Expand Down
11 changes: 7 additions & 4 deletions taxcalc/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ class instance: Calculator

def __init__(self, policy=None, records=None, verbose=False,
sync_years=True, consumption=None):
# pylint: disable=too-many-arguments,too-many-branches
# pylint: disable=too-many-arguments,too-many-positional-arguments
# pylint: disable=too-many-branches
if isinstance(policy, Policy):
self.__policy = copy.deepcopy(policy)
else:
Expand Down Expand Up @@ -625,8 +626,8 @@ def mtr(self, variable_str='e00200p',
'e20100', Charity non-cash contributions;
'k1bx14p', Partnership income (also included in e26270 and e02000).
"""
# pylint: disable=too-many-arguments,too-many-statements
# pylint: disable=too-many-locals,too-many-branches
# pylint: disable=too-many-arguments,too-many-positional-arguments
# pylint: disable=too-many-locals,too-many-branches,too-many-statements
assert not zero_out_calculated_vars or not calc_all_already_called
# check validity of variable_str parameter
if variable_str not in Calculator.MTR_VALID_VARIABLES:
Expand Down Expand Up @@ -823,7 +824,9 @@ def mtr_graph(self, calc,
-------
graph that is a bokeh.plotting figure object
"""
# pylint: disable=too-many-arguments,too-many-locals
# pylint: disable=too-many-arguments,too-many-positional-arguments
# pylint: disable=too-many-locals

# check that two Calculator objects are comparable
assert isinstance(calc, Calculator)
assert calc.current_year == self.current_year
Expand Down
7 changes: 3 additions & 4 deletions taxcalc/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ class Data():
-------
class instance: Data
"""
# suppress pylint warnings about uppercase variable names:
# pylint: disable=invalid-name
# suppress pylint warnings about too many class instance attributes:
# pylint: disable=too-many-instance-attributes
# pylint: disable=too-many-instance-attributes,invalid-name

__metaclass__ = abc.ABCMeta

Expand All @@ -75,6 +72,8 @@ class instance: Data

def __init__(self, data, start_year, gfactors=None,
weights=None, weights_scale=0.01):
# pylint: disable=too-many-arguments,too-many-positional-arguments

# initialize data variable info sets and read variable information
self.INTEGER_READ_VARS = set()
self.MUST_READ_VARS = set()
Expand Down
38 changes: 25 additions & 13 deletions taxcalc/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class Parameters(pt.Parameters):

def __init__(self, start_year=None, num_years=None, last_known_year=None,
removed=None, redefined=None, wage_indexed=None, **kwargs):
# pylint: disable=too-many-arguments,too-many-positional-arguments

# In case we need to wait for this to be called from the
# initialize method for legacy reasons.
if not start_year or not num_years:
Expand Down Expand Up @@ -134,8 +136,10 @@ def adjust(
{
"standard_deduction": [
{"year": 2024, "marital_status": "single", "value": 10000.0},
{"year": 2024, "marital_status": "joint", "value": 10000.0}
{"year": 2024, "marital_status": "single",
"value": 10000.0},
{"year": 2024, "marital_status": "joint",
"value": 10000.0}
],
"ss_rate": [{"year": 2024, "value": 0.2}]}
}
Expand All @@ -152,7 +156,7 @@ def adjust(
adjustment : Dict
Parsed paremeter dictionary
""" # noqa
"""
if print_warnings:
_data = copy.deepcopy(self._data)
kwargs["ignore_warnings"] = False
Expand Down Expand Up @@ -360,7 +364,7 @@ def adjust_with_indexing(self, params_or_path, **kwargs):
):
continue
if self._data[param].get("indexed", False):
to_delete[param] = self.sel[param]["_auto"] == True # noqa
to_delete[param] = self.sel[param]["_auto"] == True
needs_reset.append(param)

self.delete(to_delete, **kwargs)
Expand Down Expand Up @@ -409,7 +413,8 @@ def adjust_with_indexing(self, params_or_path, **kwargs):
]
self.delete(
{
base_param: self.sel[base_param]["year"] > min_adj_year # noqa
base_param:
self.sel[base_param]["year"] > min_adj_year
}
)
super().adjust({base_param: vos}, **kwargs)
Expand Down Expand Up @@ -521,7 +526,9 @@ def initialize(self, start_year, num_years, last_known_year=None,
Legacy method for initializing a Parameters instance. Projects
should use the __init__ method in the future.
"""
# case where project hasn't been initialized yet.
# pylint: disable=too-many-arguments,too-many-positional-arguments

# Handle case where project hasn't been initialized yet
if getattr(self, "_data", None) is None:
return Parameters.__init__(
self, start_year, num_years, last_known_year=last_known_year,
Expand Down Expand Up @@ -552,13 +559,15 @@ def _update(self, revision, print_warnings, raise_errors):
{
"standard_deduction": [
{"year": 2024, "marital_status": "single", "value": 10000.0},
{"year": 2024, "marital_status": "joint", "value": 10000.0}
{"year": 2024, "marital_status": "single",
"value": 10000.0},
{"year": 2024, "marital_status": "joint",
"value": 10000.0}
],
"ss_rate": [{"year": 2024, "value": 0.2}]}
}
""" # noqa: E501
"""
if not isinstance(revision, dict):
raise pt.ValidationError(
{"errors": {"schema": "Revision must be a dictionary."}},
Expand Down Expand Up @@ -697,14 +706,17 @@ def _read_json_revision(obj, topkey):
Some examples of valid links are:
- HTTP: ``https://raw.githubusercontent.com/PSLmodels/Tax-Calculator/master/taxcalc/reforms/2017_law.json``
- HTTP: ``https://raw.githubusercontent.com/PSLmodels/Tax-Calculator/
master/taxcalc/reforms/2017_law.json``
- Github API: ``github://PSLmodels:Tax-Calculator@master/taxcalc/reforms/2017_law.json``
- Github API: ``github://PSLmodels:Tax-Calculator@master/taxcalc/
reforms/2017_law.json``
Checkout the ParamTools
`docs <https://paramtools.dev/_modules/paramtools/parameters.html#Parameters.read_params>`_
`docs <https://paramtools.dev/_modules/paramtools/
parameters.html#Parameters.read_params>`_
for more information on valid file URLs.
""" # noqa
"""
# embedded function used only in _read_json_revision staticmethod
def convert_year_to_int(syr_dict):
"""
Expand Down
1 change: 1 addition & 0 deletions taxcalc/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def __init__(self,
adjust_ratios=PUF_RATIOS_FILENAME,
exact_calculations=False,
weights_scale=0.01):
# pylint: disable=too-many-positional-arguments
# pylint: disable=no-member,too-many-branches
if isinstance(weights, str):
weights = os.path.join(Records.CODE_PATH, weights)
Expand Down
12 changes: 7 additions & 5 deletions taxcalc/taxcalcio.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class instance: TaxCalcIO

def __init__(self, input_data, tax_year, baseline, reform, assump,
outdir=None):
# pylint: disable=too-many-arguments,too-many-locals
# pylint: disable=too-many-branches,too-many-statements
# pylint: disable=too-many-arguments,too-many-positional-arguments
# pylint: disable=too-many-branches,too-many-statements,too-many-locals
self.gf_reform = None
self.errmsg = ''
# check name and existence of INPUT file
Expand Down Expand Up @@ -246,8 +246,8 @@ def init(self, input_data, tax_year, baseline, reform, assump,
specifies whether or not exact tax calculations are done without
any smoothing of "stair-step" provisions in the tax law.
"""
# pylint: disable=too-many-arguments,too-many-locals
# pylint: disable=too-many-statements,too-many-branches
# pylint: disable=too-many-arguments,too-many-positional-arguments
# pylint: disable=too-many-statements,too-many-branches,too-many-locals
self.errmsg = ''
# instantiate base and reform GrowFactors objects
if self.tmd_input_data:
Expand Down Expand Up @@ -494,7 +494,8 @@ def analyze(self, writing_output_file=False,
-------
Nothing
"""
# pylint: disable=too-many-arguments,too-many-branches,too-many-locals
# pylint: disable=too-many-arguments,too-many-positional-arguments
# pylint: disable=too-many-branches,too-many-locals
if self.puf_input_data and self.calc.reform_warnings:
warn = 'PARAMETER VALUE WARNING(S): {}\n{}{}' # pragma: no cover
print( # pragma: no cover
Expand Down Expand Up @@ -599,6 +600,7 @@ def write_sqldb_file(self, dump_varset, mtr_paytax, mtr_inctax,
"""
Write dump output to SQLite3 database table dump.
"""
# pylint: disable=too-many-arguments,too-many-positional-arguments
db_fname = self._output_filename.replace('.csv', '.db')
dbcon = sqlite3.connect(db_fname)
# write baseline table
Expand Down
4 changes: 2 additions & 2 deletions taxcalc/tests/test_compatible_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ def test_compatible_data(cps_subsample, puf_subsample,
at least one of these reforms when using datasets marked compatible
and does not differ when using datasets marked as incompatible.
"""
# pylint: disable=too-many-arguments,too-many-locals
# pylint: disable=too-many-statements,too-many-branches
# pylint: disable=too-many-arguments,too-many-positional-arguments
# pylint: disable=too-many-statements,too-many-branches,too-many-locals

# Check NPARAMS value
assert NPARAMS == len(allparams)
Expand Down
3 changes: 1 addition & 2 deletions taxcalc/tests/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,11 @@ def faux_function(MARS):

@iterate_jit(nopython=True)
def ret_everything(a, b, c, d, e, f):

# pylint: disable=too-many-arguments,too-many-positional-arguments
c = a + b
d = a + b
e = a + b
f = a + b

return (c, d, e,
f)

Expand Down
2 changes: 1 addition & 1 deletion taxcalc/tests/test_reforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def test_reforms(rid, test_reforms_init, tests_path, baseline_2017_law,
"""
Write actual reform results to files.
"""
# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments,too-many-positional-arguments
assert test_reforms_init == NUM_REFORMS
actual = reform_results(rid, reforms_dict[str(rid)],
puf_subsample, baseline_2017_law)
Expand Down
3 changes: 2 additions & 1 deletion taxcalc/tests/test_taxcalcio.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ def test_init_errors(reformfile0, errorreformfile, errorassumpfile,
"""
Ensure error messages generated correctly by TaxCalcIO.init method.
"""
# pylint: disable=too-many-arguments,too-many-locals,too-many-branches
# pylint: disable=too-many-arguments,too-many-positional-arguments
# pylint: disable=too-many-locals,too-many-branches
recdict = {'RECID': 1, 'MARS': 1, 'e00300': 100000, 's006': 1e8}
recdf = pd.DataFrame(data=recdict, index=[0])
# test TaxCalcIO ctor
Expand Down
11 changes: 6 additions & 5 deletions taxcalc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ def add_quantile_table_row_variable(dframe, income_measure, num_quantiles,
and the top decile is broken into three subgroups
(90-95, 95-99, and top 1%).
"""
# pylint: disable=too-many-arguments,too-many-locals
# pylint: disable=too-many-arguments,too-many-positional-arguments
# pylint: disable=too-many-locals
assert isinstance(dframe, pd.DataFrame)
assert income_measure in dframe
assert 's006' in dframe
Expand Down Expand Up @@ -854,8 +855,8 @@ def mtr_graph_data(vdf, year,
-------
dictionary object suitable for passing to xtr_graph_plot utility function
"""
# pylint: disable=too-many-arguments,too-many-statements
# pylint: disable=too-many-locals,too-many-branches
# pylint: disable=too-many-arguments,,too-many-positional-arguments
# pylint: disable=too-many-locals,too-many-branches,too-many-statements
# check validity of function arguments
# . . check income_measure value
weighting_function = weighted_mean
Expand Down Expand Up @@ -1148,7 +1149,7 @@ def xtr_graph_plot(data,
raster graphics file. There is no option to make the bokeh.plotting
figure generate a vector graphics file such as an EPS file.
"""
# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments,too-many-positional-arguments
if title == '':
title = data['title']
fig = bp.figure(width=width, height=height, title=title)
Expand Down Expand Up @@ -1286,7 +1287,7 @@ def pch_graph_plot(data,
-----
See Notes to xtr_graph_plot function.
"""
# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments,too-many-positional-arguments
if title == '':
title = data['title']
fig = bp.figure(width=width, height=height, title=title)
Expand Down

0 comments on commit 84c2439

Please sign in to comment.