diff --git a/taxcalc/parameters.py b/taxcalc/parameters.py index aaf25f7a8..dfd2c0291 100644 --- a/taxcalc/parameters.py +++ b/taxcalc/parameters.py @@ -506,18 +506,23 @@ def get_index_rate(self, param, label_to_extend_val): def set_rates(self): """ - This method is implemented by classes inheriting - Parameters. + This method is implemented by classes inheriting Parameters. """ raise NotImplementedError() def wage_growth_rates(self, year=None): + """ + Return wage growth rates used in parameter indexing. + """ if year is not None: syr = max(self.start_year, self._gfactors.first_year) return self._wage_growth_rates[year - syr] return self._wage_growth_rates or [] def inflation_rates(self, year=None): + """ + Return price inflation rates used in parameter indexing. + """ if year is not None: syr = max(self.start_year, self._gfactors.first_year) return self._inflation_rates[year - syr] @@ -665,30 +670,37 @@ def _update(self, revision, print_warnings, raise_errors): ) def set_year(self, year): + """Specify parameter year""" self.set_state(year=year) @property def current_year(self): + """Propery docstring""" return self.label_grid["year"][0] @property def start_year(self): + """Propery docstring""" return self._stateless_label_grid["year"][0] @property def end_year(self): + """Propery docstring""" return self._stateless_label_grid["year"][-1] @property def num_years(self): + """Propery docstring""" return self.end_year - self.start_year + 1 @property def parameter_warnings(self): + """Propery docstring""" return self.errors or {} @property def parameter_errors(self): + """Propery docstring""" return self.errors or {} @staticmethod @@ -760,6 +772,9 @@ def convert_year_to_int(syr_dict): return convert_year_to_int(single_dict) def metadata(self): + """ + Return parameter specification. + """ return self.specification(meta_data=True, use_state=False) @staticmethod diff --git a/taxcalc/tests/conftest.py b/taxcalc/tests/conftest.py index e75ce4545..631911f94 100644 --- a/taxcalc/tests/conftest.py +++ b/taxcalc/tests/conftest.py @@ -16,57 +16,55 @@ @pytest.fixture def skip_jit(monkeypatch): + """Fixture docstring""" monkeypatch.setenv("TESTING", "True") yield @pytest.fixture(scope='session') def tests_path(): + """Fixture docstring""" return os.path.abspath(os.path.dirname(__file__)) @pytest.fixture(scope='session') def cps_path(tests_path): + """Fixture docstring""" return os.path.join(tests_path, '..', 'cps.csv.gz') @pytest.fixture(scope='session') def cps_fullsample(cps_path): + """Fixture docstring""" return pandas.read_csv(cps_path) @pytest.fixture(scope='session') def cps_subsample(cps_fullsample): + """Fixture docstring""" # draw smaller cps.csv subsample than in test_cpscsv.py return cps_fullsample.sample(frac=0.01, random_state=123456789) @pytest.fixture(scope='session') def puf_path(tests_path): + """Fixture docstring""" return os.path.join(tests_path, '..', '..', 'puf.csv') @pytest.fixture(scope='session') def puf_fullsample(puf_path): + """Fixture docstring""" return pandas.read_csv(puf_path) @pytest.fixture(scope='session') def puf_subsample(puf_fullsample): + """Fixture docstring""" # draw same puf.csv subsample as in test_pufcsv.py return puf_fullsample.sample(frac=0.05, random_state=2222) -@pytest.fixture(scope='session') -def tmd_path(tests_path): - return os.path.join(tests_path, '..', '..', 'tmd.csv') - - -@pytest.fixture(scope='session') -def tmd_fullsample(tmd_path): - return pandas.read_csv(tmd_path) - - @pytest.fixture(scope='session', name='test_reforms_init') def fixture_test_reforms(tests_path): """ diff --git a/taxcalc/tests/test_consumption.py b/taxcalc/tests/test_consumption.py index 157823fe7..86144dad1 100644 --- a/taxcalc/tests/test_consumption.py +++ b/taxcalc/tests/test_consumption.py @@ -13,10 +13,12 @@ def test_start_year_consistency(): + """Test docstring""" assert Consumption.JSON_START_YEAR == Policy.JSON_START_YEAR def test_validity_of_consumption_vars_set(): + """Test docstring""" records_varinfo = Records(data=None) assert Consumption.RESPONSE_VARS.issubset(records_varinfo.USABLE_READ_VARS) useable_vars = set(['housing', 'snap', 'tanf', 'vet', 'wic', @@ -25,6 +27,7 @@ def test_validity_of_consumption_vars_set(): def test_update_consumption(): + """Test docstring""" consump = Consumption() consump.update_consumption({}) revision = { @@ -61,6 +64,7 @@ def test_update_consumption(): def test_incorrect_update_consumption(): + """Test docstring""" with pytest.raises(paramtools.ValidationError): Consumption().update_consumption([]) with pytest.raises(paramtools.ValidationError): @@ -78,6 +82,7 @@ def test_incorrect_update_consumption(): def test_future_update_consumption(): + """Test docstring""" consump = Consumption() assert consump.current_year == consump.start_year assert consump.has_response() is False @@ -101,6 +106,7 @@ def test_future_update_consumption(): def test_consumption_default_data(): + """Test docstring""" consump = Consumption() pdata = consump.specification(meta_data=True, ignore_state=True) for pname in pdata.keys(): @@ -111,6 +117,7 @@ def test_consumption_default_data(): def test_consumption_response(cps_subsample): + """Test docstring""" # pylint: disable=too-many-locals consump = Consumption() mpc = 0.5 diff --git a/taxcalc/tests/test_decorators.py b/taxcalc/tests/test_decorators.py index c80fa1758..05e53f199 100644 --- a/taxcalc/tests/test_decorators.py +++ b/taxcalc/tests/test_decorators.py @@ -17,6 +17,7 @@ def test_create_apply_function_string(): + """Test docstring""" ans = create_apply_function_string(['a', 'b', 'c'], ['d', 'e'], []) exp = ("def ap_func(x_0,x_1,x_2,x_3,x_4):\n" " for i in range(len(x_0)):\n" @@ -26,6 +27,7 @@ def test_create_apply_function_string(): def test_create_apply_function_string_with_params(): + """Test docstring""" ans = create_apply_function_string(['a', 'b', 'c'], ['d', 'e'], ['d']) exp = ("def ap_func(x_0,x_1,x_2,x_3,x_4):\n" " for i in range(len(x_0)):\n" @@ -35,6 +37,7 @@ def test_create_apply_function_string_with_params(): def test_create_toplevel_function_string_mult_outputs(): + """Test docstring""" ans = create_toplevel_function_string(['a', 'b'], ['d', 'e'], ['pm', 'pm', 'pf', 'pm']) exp = '' @@ -59,6 +62,7 @@ def test_create_toplevel_function_string_mult_outputs(): def test_create_toplevel_function_string(): + """Test docstring""" ans = create_toplevel_function_string(['a'], ['d', 'e'], ['pm', 'pf', 'pm']) exp = '' @@ -82,12 +86,14 @@ def test_create_toplevel_function_string(): def some_calc(x, y, z): + """Function docstring""" a = x + y b = x + y + z return (a, b) def test_make_apply_function(): + """Test docstring""" ans_do_jit = make_apply_function(some_calc, ['a', 'b'], ['x', 'y', 'z'], [], do_jit=True, no_python=True) assert ans_do_jit @@ -98,12 +104,14 @@ def test_make_apply_function(): @apply_jit(["a", "b"], ["x", "y", "z"], nopython=True) def magic_calc(x, y, z): + """Function docstring""" a = x + y b = x + y + z return (a, b) def magic(pm, pf): + """Function docstring""" # Adjustments outputs = pf.a, pf.b = magic_calc(pm, pf) header = ['a', 'b'] @@ -112,18 +120,21 @@ def magic(pm, pf): @iterate_jit(nopython=True) def magic_calc2(x, y, z): + """Function docstring""" a = x + y b = x + y + z return (a, b) class Foo: + """Foo class""" # pylint: disable=too-few-public-methods,too-many-instance-attributes pass @iterate_jit(nopython=True) def faux_function(mars): + """Function docstring""" if mars == 1: var = 2 else: @@ -133,15 +144,18 @@ def faux_function(mars): @iterate_jit(nopython=True) def ret_everything(a, b, c, d, e, f): + """Function docstring""" # 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) + return (c, d, e, + f) def test_magic_apply_jit(): + """Test docstring""" pm = Foo() pf = Foo() pm.a = np.ones((5,)) @@ -155,6 +169,7 @@ def test_magic_apply_jit(): def test_magic_apply_jit_swap(): + """Test docstring""" pm = Foo() pf = Foo() pm.a = np.ones((5,)) @@ -168,6 +183,7 @@ def test_magic_apply_jit_swap(): def test_magic_iterate_jit(): + """Test docstring""" pm = Foo() pf = Foo() pm.a = np.ones((1, 5)) @@ -181,6 +197,7 @@ def test_magic_iterate_jit(): def test_faux_function_iterate_jit(): + """Test docstring""" pm = Foo() pf = Foo() pf.mars = np.ones((5,)) @@ -191,6 +208,7 @@ def test_faux_function_iterate_jit(): def test_ret_everything_iterate_jit(): + """Test docstring""" pm = Foo() pf = Foo() pf.a = np.ones((5,)) @@ -207,12 +225,14 @@ def test_ret_everything_iterate_jit(): @iterate_jit(nopython=True) def magic_calc3(x, y, z): + """Function docstring""" a = x + y b = a + z return (a, b) def test_function_takes_kwarg(): + """Test docstring""" pm = Foo() pf = Foo() pm.a = np.ones((1, 5)) @@ -228,12 +248,14 @@ def test_function_takes_kwarg(): @iterate_jit(nopython=True) def magic_calc4(x, y, z): + """Function docstring""" a = x + y b = a + z return (a, b) def test_function_no_parameters_listed(): + """Test docstring""" pm = Foo() pf = Foo() pm.a = np.ones((1, 5)) @@ -249,12 +271,14 @@ def test_function_no_parameters_listed(): @iterate_jit(parameters=['w'], nopython=True) def magic_calc5(w, x, y, z): + """Function docstring""" a = x + y b = w[0] + x + y + z return (a, b) def test_function_parameters_optional(): + """Test docstring""" pm = Foo() pf = Foo() pm.a = np.ones((1, 5)) @@ -270,23 +294,27 @@ def test_function_parameters_optional(): def unjittable_function1(w, x, y, z): + """Function docstring""" a = x + y b = w[0] + x + y + z def unjittable_function2(w, x, y, z): + """Function docstring""" a = x + y b = w[0] + x + y + z return (a, b, c) def test_iterate_jit_raises_on_no_return(): + """Test docstring""" with pytest.raises(ValueError): ij = iterate_jit(parameters=['w'], nopython=True) ij(unjittable_function1) def test_iterate_jit_raises_on_unknown_return_argument(): + """Test docstring""" ij = iterate_jit(parameters=['w'], nopython=True) uf2 = ij(unjittable_function2) pm = Foo() @@ -302,6 +330,7 @@ def test_iterate_jit_raises_on_unknown_return_argument(): def magic_calc6(w, x, y, z): + """Function docstring""" a = x + y b = w[0] + x + y + z return (a, b) diff --git a/taxcalc/tests/test_growdiff.py b/taxcalc/tests/test_growdiff.py index e9877f913..611512a50 100644 --- a/taxcalc/tests/test_growdiff.py +++ b/taxcalc/tests/test_growdiff.py @@ -13,10 +13,12 @@ def test_start_year_consistency(): + """Test docstring""" assert GrowDiff.JSON_START_YEAR == Policy.JSON_START_YEAR def test_update_and_apply_growdiff(): + """Test docstring""" gdiff = GrowDiff() # update GrowDiff instance diffs = { @@ -45,6 +47,7 @@ def test_update_and_apply_growdiff(): def test_has_any_response(): + """Test docstring""" start_year = GrowDiff.JSON_START_YEAR gdiff = GrowDiff() assert gdiff.current_year == start_year diff --git a/taxcalc/tests/test_parameters.py b/taxcalc/tests/test_parameters.py index 46ec67127..bb0404811 100644 --- a/taxcalc/tests/test_parameters.py +++ b/taxcalc/tests/test_parameters.py @@ -297,6 +297,7 @@ def test_parameters_mentioned(tests_path, jfname, pfname): # following tests access private methods, so pylint: disable=protected-access class ArrayParams(Parameters): + """ArrayParams class""" defaults = { "schema": { "labels": { @@ -416,6 +417,7 @@ def test_expand_xd_errors(): def test_expand_empty(): + """Test docstring""" params = ArrayParams(label_to_extend=None, array_first=False) params.sort_values() one_dim = copy.deepcopy(params.one_dim) @@ -427,6 +429,7 @@ def test_expand_empty(): def test_expand_1d_scalar(): + """Test docstring""" yrs = 12 val = 10.0 exp = np.array([val * math.pow(1.02, i) for i in range(0, yrs)]) diff --git a/taxcalc/tests/test_records.py b/taxcalc/tests/test_records.py index 6dd0131d6..498963d2d 100644 --- a/taxcalc/tests/test_records.py +++ b/taxcalc/tests/test_records.py @@ -16,6 +16,7 @@ def test_incorrect_records_instantiation(cps_subsample): + """Test docstring""" with pytest.raises(ValueError): recs = Records(data=[]) with pytest.raises(ValueError): @@ -31,6 +32,7 @@ def test_incorrect_records_instantiation(cps_subsample): def test_correct_records_instantiation(cps_subsample): + """Test docstring""" rec1 = Records.cps_constructor(data=cps_subsample, gfactors=None) assert rec1 assert np.all(rec1.MARS != 0) @@ -55,6 +57,7 @@ def test_correct_records_instantiation(cps_subsample): def test_read_cps_data(cps_fullsample): + """Test docstring""" data = Records.read_cps_data() assert data.equals(cps_fullsample) @@ -118,12 +121,14 @@ def test_read_cps_data(cps_fullsample): ) ]) def test_read_data(csv): + """Test docstring""" df = pd.read_csv(StringIO(csv)) with pytest.raises(ValueError): Records(data=df) def test_for_duplicate_names(): + """Test docstring""" records_varinfo = Records(data=None) varnames = set() for varname in records_varinfo.USABLE_READ_VARS: diff --git a/taxcalc/tests/test_taxcalcio.py b/taxcalc/tests/test_taxcalcio.py index 93d7a5f59..a0327be08 100644 --- a/taxcalc/tests/test_taxcalcio.py +++ b/taxcalc/tests/test_taxcalcio.py @@ -746,6 +746,7 @@ def fixture_regression_reform_file(): def test_error_message_parsed_correctly(regression_reform_file): + """Test docstring""" tcio = TaxCalcIO(input_data=pd.read_csv(StringIO(RAWINPUT)), tax_year=2022, baseline=regression_reform_file.name,