diff --git a/acro/acro_tables.py b/acro/acro_tables.py index cac4a91..be8da02 100644 --- a/acro/acro_tables.py +++ b/acro/acro_tables.py @@ -145,7 +145,7 @@ def crosstab( # pylint: disable=too-many-arguments,too-many-locals agg_func = get_aggfuncs(aggfunc) # requested table - table: DataFrame = pd.crosstab( # type: ignore + table: DataFrame = pd.crosstab( index, columns, values, @@ -321,7 +321,7 @@ def pivot_table( # pylint: disable=too-many-arguments,too-many-locals # threshold check agg = [agg_threshold] * n_agg if n_agg > 1 else agg_threshold - t_values = pd.pivot_table( # type: ignore + t_values = pd.pivot_table( data, values, index, columns, aggfunc=agg, margins=margins ) masks["threshold"] = t_values @@ -329,25 +329,25 @@ def pivot_table( # pylint: disable=too-many-arguments,too-many-locals if aggfunc is not None: # check for negative values -- currently unsupported agg = [agg_negative] * n_agg if n_agg > 1 else agg_negative - negative = pd.pivot_table( # type: ignore + negative = pd.pivot_table( data, values, index, columns, aggfunc=agg, margins=margins ) if negative.to_numpy().sum() > 0: masks["negative"] = negative # p-percent check agg = [agg_p_percent] * n_agg if n_agg > 1 else agg_p_percent - masks["p-ratio"] = pd.pivot_table( # type: ignore + masks["p-ratio"] = pd.pivot_table( data, values, index, columns, aggfunc=agg, margins=margins ) # nk values check agg = [agg_nk] * n_agg if n_agg > 1 else agg_nk - masks["nk-rule"] = pd.pivot_table( # type: ignore + masks["nk-rule"] = pd.pivot_table( data, values, index, columns, aggfunc=agg, margins=margins ) # check for missing values -- currently unsupported if CHECK_MISSING_VALUES: agg = [agg_missing] * n_agg if n_agg > 1 else agg_missing - masks["missing"] = pd.pivot_table( # type: ignore + masks["missing"] = pd.pivot_table( data, values, index, columns, aggfunc=agg, margins=margins ) @@ -782,7 +782,7 @@ def create_crosstab_masks( # pylint: disable=too-many-arguments,too-many-locals logger.info( "If there are multiple modes, one of them is randomly selected and displayed." ) - masks["all-values-are-same"] = pd.crosstab( # type: ignore + masks["all-values-are-same"] = pd.crosstab( index, columns, values, @@ -791,7 +791,7 @@ def create_crosstab_masks( # pylint: disable=too-many-arguments,too-many-locals dropna=dropna, ) else: - t_values = pd.crosstab( # type: ignore + t_values = pd.crosstab( index, columns, values=values, @@ -815,13 +815,13 @@ def create_crosstab_masks( # pylint: disable=too-many-arguments,too-many-locals t_values = t_values < THRESHOLD masks["threshold"] = t_values # check for negative values -- currently unsupported - negative = pd.crosstab( # type: ignore + negative = pd.crosstab( index, columns, values, aggfunc=neg_funcs, margins=margins ) if negative.to_numpy().sum() > 0: masks["negative"] = negative # p-percent check - masks["p-ratio"] = pd.crosstab( # type: ignore + masks["p-ratio"] = pd.crosstab( index, columns, values, @@ -830,17 +830,17 @@ def create_crosstab_masks( # pylint: disable=too-many-arguments,too-many-locals dropna=dropna, ) # nk values check - masks["nk-rule"] = pd.crosstab( # type: ignore + masks["nk-rule"] = pd.crosstab( index, columns, values, aggfunc=nk_funcs, margins=margins, dropna=dropna ) # check for missing values -- currently unsupported if CHECK_MISSING_VALUES: - masks["missing"] = pd.crosstab( # type: ignore + masks["missing"] = pd.crosstab( index, columns, values, aggfunc=missing_funcs, margins=margins ) else: # threshold check- doesn't matter what we pass for value - t_values = pd.crosstab( # type: ignore + t_values = pd.crosstab( index, columns, values=None, @@ -1499,7 +1499,7 @@ def crosstab_with_totals( # pylint: disable=too-many-arguments,too-many-locals if crosstab: index_new, columns_new = get_index_columns(index, columns, data) # apply the crosstab with the new index and columns - table = pd.crosstab( # type: ignore + table = pd.crosstab( index_new, columns_new, values=values, @@ -1534,7 +1534,7 @@ def crosstab_with_totals( # pylint: disable=too-many-arguments,too-many-locals logger.setLevel(previous_level) else: - table = pd.pivot_table( # type: ignore + table = pd.pivot_table( data=data, values=values, index=index, @@ -1618,7 +1618,7 @@ def manual_crossstab_with_totals( # pylint: disable=too-many-arguments table = recalculate_margin(table, margins_name) elif aggfunc == "mean": - count_table = pd.crosstab( # type: ignore + count_table = pd.crosstab( index=index, columns=columns, values=values, diff --git a/pyproject.toml b/pyproject.toml index 1c0a890..2500cb2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,14 +23,14 @@ lint.select = [ "ICN", # flake8-import-conventions "N", # pep8-naming # "PD", # pandas-vet -# "PGH", # pygrep-hooks + "PGH", # pygrep-hooks "PIE", # flake8-pie # "PL", # Pylint "PLC", # Pylint "PLE", # Pylint # "PLR", # Pylint # "PLW", # Pylint -# "PT", # flake8-pytest-style + "PT", # flake8-pytest-style "Q", # flake8-quotes # "RET", # flake8-return "RUF100", # Ruff-specific diff --git a/test/test_initial.py b/test/test_initial.py index 28df518..55d75e9 100644 --- a/test/test_initial.py +++ b/test/test_initial.py @@ -17,7 +17,7 @@ PATH: str = "RES_PYTEST" -@pytest.fixture +@pytest.fixture() def data() -> pd.DataFrame: """Load test data.""" path = os.path.join("data", "test_data.dta") @@ -25,7 +25,7 @@ def data() -> pd.DataFrame: return data -@pytest.fixture +@pytest.fixture() def acro() -> ACRO: """Initialise ACRO.""" return ACRO(suppress=True) @@ -334,14 +334,14 @@ def test_output_removal(data, acro, monkeypatch): assert output_1.summary == correct_summary acro.print_outputs() # remove something that is not there - with pytest.raises(ValueError): + with pytest.raises(ValueError, match="unable to remove 123, key not found"): acro.remove_output("123") shutil.rmtree(PATH) def test_load_output(): """Empty array when loading output.""" - with pytest.raises(ValueError): + with pytest.raises(ValueError, match="error loading output"): record.load_output(PATH, []) @@ -350,7 +350,7 @@ def test_finalise_invalid(data, acro): _ = acro.crosstab(data.year, data.grant_type) output_0 = acro.results.get_index(0) output_0.exception = "Let me have it" - with pytest.raises(ValueError): + with pytest.raises(ValueError, match="Invalid file extension.*"): _ = acro.finalise(PATH, "123") @@ -405,10 +405,10 @@ def test_rename_output(data, acro): assert orig_name not in results.get_keys() assert os.path.exists(f"{PATH}/{new_name}_0.csv") # rename an output that doesn't exist - with pytest.raises(ValueError): + with pytest.raises(ValueError, match="unable to rename 123, key not found"): acro.rename_output("123", "name") # rename an output to another that already exists - with pytest.raises(ValueError): + with pytest.raises(ValueError, match="unable to rename, cross_table .* exists"): acro.rename_output("output_1", "cross_table") shutil.rmtree(PATH) @@ -427,7 +427,7 @@ def test_add_comments(data, acro): acro.add_comments(output_0.uid, comment_1) assert output_0.comments == [comment, comment_1] # add a comment to something that is not there - with pytest.raises(ValueError): + with pytest.raises(ValueError, match="unable to find 123, key not found"): acro.add_comments("123", "comment") shutil.rmtree(PATH) @@ -480,7 +480,7 @@ def test_suppression_error(caplog): def test_adding_exception(acro): """Adding an exception to an output that doesn't exist test.""" - with pytest.raises(ValueError): + with pytest.raises(ValueError, match="unable to add exception: output_0 .*"): acro.add_exception("output_0", "Let me have it") @@ -597,14 +597,14 @@ def test_hierachical_aggregation(data, acro): def test_single_values_column(data, acro): """Pandas does not allows multiple arrays for values.""" - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=".*specify a single values column.*"): _ = acro.crosstab( data.year, data.grant_type, values=[data.inc_activity, data.inc_activity], aggfunc="mean", ) - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=".*specify a single values column.*"): _ = acro.crosstab(data.year, data.grant_type, values=None, aggfunc="mean") diff --git a/test/test_stata17_interface.py b/test/test_stata17_interface.py index 729b196..b75f6c8 100644 --- a/test/test_stata17_interface.py +++ b/test/test_stata17_interface.py @@ -25,7 +25,7 @@ # return ACRO() -@pytest.fixture +@pytest.fixture() def data() -> pd.DataFrame: """Load test data.""" path = os.path.join("data", "test_data.dta") diff --git a/test/test_stata_interface.py b/test/test_stata_interface.py index 2cb80d4..9531dce 100644 --- a/test/test_stata_interface.py +++ b/test/test_stata_interface.py @@ -26,7 +26,7 @@ # return ACRO() -@pytest.fixture +@pytest.fixture() def data() -> pd.DataFrame: """Load test data.""" path = os.path.join("data", "test_data.dta")