Skip to content

Commit

Permalink
Backport PR #51312 on branch 2.0.x (CI/TST: Enable -W error:::pandas …
Browse files Browse the repository at this point in the history
…in pyproject.toml) (#51570)

Backport PR #51312: CI/TST: Enable -W error:::pandas in pyproject.toml

Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>
  • Loading branch information
meeseeksmachine and mroeschke committed Feb 23, 2023
1 parent 94cfc4a commit dcbff60
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 55 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/macos-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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' }}
Expand Down
7 changes: 0 additions & 7 deletions ci/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
12 changes: 12 additions & 0 deletions pandas/_testing/_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
nullcontext,
)
import re
import sys
from typing import (
Generator,
Literal,
Expand Down Expand Up @@ -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 <ssl.SSLSocket" in str(actual_warning.message):
continue
# GH 44844: Matplotlib leaves font files open during the entire process
# upon import. Don't make CI flaky if ResourceWarning raised
# due to these open files.
if any("matplotlib" in mod for mod in sys.modules):
continue
extra_warnings.append(
(
actual_warning.category.__name__,
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4006,10 +4006,10 @@ class animal locomotion
Get values at several indexes
>>> 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
Expand Down
27 changes: 0 additions & 27 deletions pandas/io/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/frame/test_query_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pandas/tests/groupby/test_nth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 4 additions & 5 deletions pandas/tests/io/pytables/test_retain_attributes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from warnings import catch_warnings

import pytest

from pandas._libs.tslibs import Timestamp
Expand All @@ -9,6 +7,7 @@
Series,
_testing as tm,
date_range,
errors,
read_hdf,
)
from pandas.tests.io.pytables.common import (
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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"))}
)
Expand All @@ -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)})
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/io/sas/test_byteswap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
14 changes: 11 additions & 3 deletions pandas/tests/series/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down Expand Up @@ -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)


Expand Down
3 changes: 3 additions & 0 deletions pandas/tests/test_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "**")],
Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,14 @@ doctest_optionflags = [
"ELLIPSIS",
]
filterwarnings = [
"error:::pandas",
"error::ResourceWarning",
"error::pytest.PytestUnraisableExceptionWarning",
"ignore:.*ssl.SSLSocket:pytest.PytestUnraisableExceptionWarning",
"ignore:unclosed <ssl.SSLSocket:ResourceWarning",
"ignore:.*ssl.SSLSocket:ResourceWarning",
"ignore::ResourceWarning:asyncio",
# From plotting doctests
"ignore:More than 20 figures have been opened:RuntimeWarning",
# Will be fixed in numba 0.56: https://github.com/numba/numba/issues/7758
"ignore:`np.MachAr` is deprecated:DeprecationWarning:numba",
"ignore:.*urllib3:DeprecationWarning:botocore",
Expand Down

0 comments on commit dcbff60

Please sign in to comment.