From df8a53722bf1d39cc512ba8f6b561a963eba36a1 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 22 Feb 2023 15:30:53 -0800 Subject: [PATCH] Backport PR #51312: CI/TST: Enable -W error:::pandas in pyproject.toml --- .github/workflows/macos-windows.yml | 2 -- .github/workflows/ubuntu.yml | 5 ---- ci/run_tests.sh | 7 ----- pandas/_testing/_warnings.py | 12 +++++++++ pandas/core/generic.py | 8 +++--- pandas/io/sql.py | 27 ------------------- pandas/tests/frame/test_query_eval.py | 4 ++- pandas/tests/groupby/test_groupby.py | 3 +++ pandas/tests/groupby/test_nth.py | 3 +++ .../io/pytables/test_retain_attributes.py | 9 +++---- pandas/tests/io/sas/test_byteswap.py | 1 + pandas/tests/series/test_arithmetic.py | 14 +++++++--- pandas/tests/test_expressions.py | 3 +++ pyproject.toml | 5 +++- 14 files changed, 48 insertions(+), 55 deletions(-) diff --git a/.github/workflows/macos-windows.yml b/.github/workflows/macos-windows.yml index 7446ec00a87c9..bc6ecd7c5e5d0 100644 --- a/.github/workflows/macos-windows.yml +++ b/.github/workflows/macos-windows.yml @@ -18,8 +18,6 @@ env: PANDAS_CI: 1 PYTEST_TARGET: pandas PATTERN: "not slow and not db and not network and not single_cpu" - ERROR_ON_WARNINGS: "1" - permissions: contents: read diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index efcf270d77760..7b31c5392849b 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -40,7 +40,6 @@ jobs: - name: "Minimum Versions" env_file: actions-38-minimum_versions.yaml pattern: "not slow and not network and not single_cpu" - error_on_warnings: "0" - name: "Locale: it_IT" env_file: actions-38.yaml pattern: "not slow and not network and not single_cpu" @@ -65,12 +64,10 @@ jobs: env_file: actions-310.yaml pattern: "not slow and not network and not single_cpu" pandas_copy_on_write: "1" - error_on_warnings: "0" - name: "Data Manager" env_file: actions-38.yaml pattern: "not slow and not network and not single_cpu" pandas_data_manager: "array" - error_on_warnings: "0" - name: "Pypy" env_file: actions-pypy-38.yaml pattern: "not slow and not network and not single_cpu" @@ -79,7 +76,6 @@ jobs: env_file: actions-310-numpydev.yaml pattern: "not slow and not network and not single_cpu" test_args: "-W error::DeprecationWarning -W error::FutureWarning" - error_on_warnings: "0" exclude: - env_file: actions-38.yaml pyarrow_version: "8" @@ -99,7 +95,6 @@ jobs: ENV_FILE: ci/deps/${{ matrix.env_file }} PATTERN: ${{ matrix.pattern }} EXTRA_APT: ${{ matrix.extra_apt || '' }} - ERROR_ON_WARNINGS: ${{ matrix.error_on_warnings || '1' }} LANG: ${{ matrix.lang || '' }} LC_ALL: ${{ matrix.lc_all || '' }} PANDAS_DATA_MANAGER: ${{ matrix.pandas_data_manager || 'block' }} diff --git a/ci/run_tests.sh b/ci/run_tests.sh index a48d6c1ad6580..e6de5caf955fc 100755 --- a/ci/run_tests.sh +++ b/ci/run_tests.sh @@ -30,13 +30,6 @@ if [[ "$PATTERN" ]]; then PYTEST_CMD="$PYTEST_CMD -m \"$PATTERN\"" fi -if [[ "$ERROR_ON_WARNINGS" == "1" ]]; then - for pth in $(find pandas -name '*.py' -not -path "pandas/tests/*" | sed -e 's/\.py//g' -e 's/\/__init__//g' -e 's/\//./g'); - do - PYTEST_CMD="$PYTEST_CMD -W error:::$pth" - done -fi - echo $PYTEST_CMD sh -c "$PYTEST_CMD" diff --git a/pandas/_testing/_warnings.py b/pandas/_testing/_warnings.py index 0d1076f235b1d..201aa81183301 100644 --- a/pandas/_testing/_warnings.py +++ b/pandas/_testing/_warnings.py @@ -5,6 +5,7 @@ nullcontext, ) import re +import sys from typing import ( Generator, Literal, @@ -163,6 +164,17 @@ def _assert_caught_no_extra_warnings( for actual_warning in caught_warnings: if _is_unexpected_warning(actual_warning, expected_warning): + # GH#38630 pytest.filterwarnings does not suppress these. + if actual_warning.category == ResourceWarning: + # GH 44732: Don't make the CI flaky by filtering SSL-related + # ResourceWarning from dependencies + if "unclosed >> df.xs(('mammal', 'dog')) - num_legs num_wings - locomotion - walks 4 0 + >>> df.xs(('mammal', 'dog', 'walks')) + num_legs 4 + num_wings 0 + Name: (mammal, dog, walks), dtype: int64 Get values at specified index and level diff --git a/pandas/io/sql.py b/pandas/io/sql.py index 4e86166ef512d..7dedd705f8c70 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -632,36 +632,9 @@ def read_sql( >>> pd.read_sql('test_data', 'postgres:///db_name') # doctest:+SKIP Apply date parsing to columns through the ``parse_dates`` argument - - >>> pd.read_sql('SELECT int_column, date_column FROM test_data', - ... conn, - ... parse_dates=["date_column"]) - int_column date_column - 0 0 2012-10-11 - 1 1 2010-12-11 - The ``parse_dates`` argument calls ``pd.to_datetime`` on the provided columns. Custom argument values for applying ``pd.to_datetime`` on a column are specified via a dictionary format: - 1. Ignore errors while parsing the values of "date_column" - - >>> pd.read_sql('SELECT int_column, date_column FROM test_data', - ... conn, - ... parse_dates={"date_column": {"errors": "ignore"}}) - int_column date_column - 0 0 2012-10-11 - 1 1 2010-12-11 - - 2. Apply a dayfirst date parsing order on the values of "date_column" - - >>> pd.read_sql('SELECT int_column, date_column FROM test_data', - ... conn, - ... parse_dates={"date_column": {"dayfirst": True}}) - int_column date_column - 0 0 2012-11-10 - 1 1 2010-11-12 - - 3. Apply custom formatting when date parsing the values of "date_column" >>> pd.read_sql('SELECT int_column, date_column FROM test_data', ... conn, diff --git a/pandas/tests/frame/test_query_eval.py b/pandas/tests/frame/test_query_eval.py index 7abc8e5eb92cc..fc0c81339de08 100644 --- a/pandas/tests/frame/test_query_eval.py +++ b/pandas/tests/frame/test_query_eval.py @@ -1332,7 +1332,9 @@ def test_query_ea_dtypes(self, dtype): # GH#50261 df = DataFrame({"a": Series([1, 2], dtype=dtype)}) ref = {2} # noqa:F841 - result = df.query("a in @ref") + warning = RuntimeWarning if dtype == "Int64" and NUMEXPR_INSTALLED else None + with tm.assert_produces_warning(warning): + result = df.query("a in @ref") expected = DataFrame({"a": Series([2], dtype=dtype, index=[1])}) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index d969ce4a2bb71..42ecdb611576b 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -2774,6 +2774,9 @@ def test_sum_of_booleans(n): tm.assert_frame_equal(result, expected) +@pytest.mark.filterwarnings( + "ignore:invalid value encountered in remainder:RuntimeWarning" +) @pytest.mark.parametrize("method", ["head", "tail", "nth", "first", "last"]) def test_groupby_method_drop_na(method): # GH 21755 diff --git a/pandas/tests/groupby/test_nth.py b/pandas/tests/groupby/test_nth.py index cf1537b42bc9f..874b37120cc23 100644 --- a/pandas/tests/groupby/test_nth.py +++ b/pandas/tests/groupby/test_nth.py @@ -789,6 +789,9 @@ def test_nth_slices_with_column_axis( tm.assert_frame_equal(result, expected) +@pytest.mark.filterwarnings( + "ignore:invalid value encountered in remainder:RuntimeWarning" +) def test_head_tail_dropna_true(): # GH#45089 df = DataFrame( diff --git a/pandas/tests/io/pytables/test_retain_attributes.py b/pandas/tests/io/pytables/test_retain_attributes.py index 67e864591626c..8ca8e624a6de2 100644 --- a/pandas/tests/io/pytables/test_retain_attributes.py +++ b/pandas/tests/io/pytables/test_retain_attributes.py @@ -1,5 +1,3 @@ -from warnings import catch_warnings - import pytest from pandas._libs.tslibs import Timestamp @@ -9,6 +7,7 @@ Series, _testing as tm, date_range, + errors, read_hdf, ) from pandas.tests.io.pytables.common import ( @@ -39,7 +38,7 @@ def test_retain_index_attributes(setup_path): ) # try to append a table with a different frequency - with catch_warnings(record=True): + with tm.assert_produces_warning(errors.AttributeConflictWarning): df2 = DataFrame( { "A": Series( @@ -75,7 +74,7 @@ def test_retain_index_attributes(setup_path): def test_retain_index_attributes2(tmp_path, setup_path): path = tmp_path / setup_path - with catch_warnings(record=True): + with tm.assert_produces_warning(errors.AttributeConflictWarning): df = DataFrame( {"A": Series(range(3), index=date_range("2000-1-1", periods=3, freq="H"))} ) @@ -93,7 +92,7 @@ def test_retain_index_attributes2(tmp_path, setup_path): assert read_hdf(path, "data").index.name == "foo" - with catch_warnings(record=True): + with tm.assert_produces_warning(errors.AttributeConflictWarning): idx2 = date_range("2001-1-1", periods=3, freq="H") idx2.name = "bar" df2 = DataFrame({"A": Series(range(3), index=idx2)}) diff --git a/pandas/tests/io/sas/test_byteswap.py b/pandas/tests/io/sas/test_byteswap.py index 2c88907df3b1d..0ef4eeb54beb3 100644 --- a/pandas/tests/io/sas/test_byteswap.py +++ b/pandas/tests/io/sas/test_byteswap.py @@ -29,6 +29,7 @@ def test_int_byteswap(read_offset, number, int_type, should_byteswap): _test(number, int_type, read_offset, should_byteswap) +@pytest.mark.filterwarnings("ignore:overflow encountered:RuntimeWarning") @given(read_offset=st.integers(0, 11), number=st.floats()) @pytest.mark.parametrize("float_type", [np.float32, np.float64]) @pytest.mark.parametrize("should_byteswap", [True, False]) diff --git a/pandas/tests/series/test_arithmetic.py b/pandas/tests/series/test_arithmetic.py index e4044feab1cbd..fa72bf4368b69 100644 --- a/pandas/tests/series/test_arithmetic.py +++ b/pandas/tests/series/test_arithmetic.py @@ -32,6 +32,7 @@ ops, ) from pandas.core.computation import expressions as expr +from pandas.core.computation.check import NUMEXPR_INSTALLED @pytest.fixture(autouse=True, params=[0, 1000000], ids=["numexpr", "python"]) @@ -349,14 +350,21 @@ def test_add_list_to_masked_array(self, val, dtype): result = [1, None, val] + ser tm.assert_series_equal(result, expected) - def test_add_list_to_masked_array_boolean(self): + def test_add_list_to_masked_array_boolean(self, request): # GH#22962 + warning = ( + UserWarning + if request.node.callspec.id == "numexpr" and NUMEXPR_INSTALLED + else None + ) ser = Series([True, None, False], dtype="boolean") - result = ser + [True, None, True] + with tm.assert_produces_warning(warning): + result = ser + [True, None, True] expected = Series([True, None, True], dtype="boolean") tm.assert_series_equal(result, expected) - result = [True, None, True] + ser + with tm.assert_produces_warning(warning): + result = [True, None, True] + ser tm.assert_series_equal(result, expected) diff --git a/pandas/tests/test_expressions.py b/pandas/tests/test_expressions.py index c241603fd7ff9..ec4f8893885f3 100644 --- a/pandas/tests/test_expressions.py +++ b/pandas/tests/test_expressions.py @@ -199,6 +199,9 @@ def test_invalid(self): result = expr._can_use_numexpr(operator.add, "+", array, array2, "evaluate") assert result + @pytest.mark.filterwarnings( + "ignore:invalid value encountered in true_divide:RuntimeWarning" + ) @pytest.mark.parametrize( "opname,op_str", [("add", "+"), ("sub", "-"), ("mul", "*"), ("truediv", "/"), ("pow", "**")], diff --git a/pyproject.toml b/pyproject.toml index 9d4166b033128..5204138fcd7ab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -395,11 +395,14 @@ doctest_optionflags = [ "ELLIPSIS", ] filterwarnings = [ + "error:::pandas", "error::ResourceWarning", "error::pytest.PytestUnraisableExceptionWarning", "ignore:.*ssl.SSLSocket:pytest.PytestUnraisableExceptionWarning", - "ignore:unclosed