Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
568c258
CI/TST: Enable -W error:::pandas in pyproject.toml
mroeschke Feb 10, 2023
294d937
Address some tests
mroeschke Feb 11, 2023
e1700cf
Merge remote-tracking branch 'upstream/main' into tst/warnings_errors…
mroeschke Feb 13, 2023
acfd1f5
filter more expected warnings in tests
mroeschke Feb 13, 2023
4ed4a11
Change examples raising warnings
mroeschke Feb 13, 2023
7d8173b
Merge remote-tracking branch 'upstream/main' into tst/warnings_errors…
mroeschke Feb 14, 2023
b926b39
Just ignore userwarning, not point of the test
mroeschke Feb 14, 2023
628bd01
remove a sql date example, ignore open plots
mroeschke Feb 14, 2023
485c95d
Merge remote-tracking branch 'upstream/main' into tst/warnings_errors…
mroeschke Feb 14, 2023
5e54f1d
Just use one example
mroeschke Feb 14, 2023
27360c1
Fix path
mroeschke Feb 14, 2023
3e6877e
Merge remote-tracking branch 'upstream/main' into tst/warnings_errors…
mroeschke Feb 15, 2023
76c360f
Merge remote-tracking branch 'upstream/main' into tst/warnings_errors…
mroeschke Feb 16, 2023
b3ce610
Add comment about filtering warning
mroeschke Feb 16, 2023
1d5faae
Merge remote-tracking branch 'upstream/main' into tst/warnings_errors…
mroeschke Feb 18, 2023
705f230
Filter out expected warning?
mroeschke Feb 18, 2023
c167b01
Merge remote-tracking branch 'upstream/main' into tst/warnings_errors…
mroeschke Feb 18, 2023
f9c4e55
Merge remote-tracking branch 'upstream/main' into tst/warnings_errors…
mroeschke Feb 19, 2023
f345e9a
Remove unneeded filter
mroeschke Feb 19, 2023
a2a56d9
Merge remote-tracking branch 'upstream/main' into tst/warnings_errors…
mroeschke Feb 19, 2023
acf3d3d
Merge remote-tracking branch 'upstream/main' into tst/warnings_errors…
mroeschke Feb 20, 2023
963625d
Try catching sockerwarning in pyproject toml
mroeschke Feb 21, 2023
e528472
Add back sslsocket filtering
mroeschke Feb 21, 2023
149b5e6
add back matplotlib error too
mroeschke Feb 21, 2023
166264e
Merge remote-tracking branch 'upstream/main' into tst/warnings_errors…
mroeschke Feb 22, 2023
f9e9ed3
include patrick's changes
mroeschke Feb 22, 2023
4c677c7
Typo
mroeschke Feb 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -4015,10 +4015,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',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed these examples because they trigger UserWarnings that the format could not be inferred. There is still an example of parse_dates at the bottom that I think fits the spirit of showing what the keyword does

... 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 @@ -397,11 +397,14 @@ doctest_optionflags = [
"ELLIPSIS",
]
filterwarnings = [
"error:::pandas",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this one mean?

Copy link
Member Author

@mroeschke mroeschke Feb 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If any unhanded warning with any message or warning class originates from the path pandas/*, treat it as as an error in the test suite.

Any subsequent filter in this list takes prescient over this one if they overlap.

"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