Skip to content

Commit df8a537

Browse files
mroeschkemeeseeksmachine
authored andcommitted
Backport PR pandas-dev#51312: CI/TST: Enable -W error:::pandas in pyproject.toml
1 parent db1bd72 commit df8a537

14 files changed

+48
-55
lines changed

.github/workflows/macos-windows.yml

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ env:
1818
PANDAS_CI: 1
1919
PYTEST_TARGET: pandas
2020
PATTERN: "not slow and not db and not network and not single_cpu"
21-
ERROR_ON_WARNINGS: "1"
22-
2321

2422
permissions:
2523
contents: read

.github/workflows/ubuntu.yml

-5
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ jobs:
4040
- name: "Minimum Versions"
4141
env_file: actions-38-minimum_versions.yaml
4242
pattern: "not slow and not network and not single_cpu"
43-
error_on_warnings: "0"
4443
- name: "Locale: it_IT"
4544
env_file: actions-38.yaml
4645
pattern: "not slow and not network and not single_cpu"
@@ -65,12 +64,10 @@ jobs:
6564
env_file: actions-310.yaml
6665
pattern: "not slow and not network and not single_cpu"
6766
pandas_copy_on_write: "1"
68-
error_on_warnings: "0"
6967
- name: "Data Manager"
7068
env_file: actions-38.yaml
7169
pattern: "not slow and not network and not single_cpu"
7270
pandas_data_manager: "array"
73-
error_on_warnings: "0"
7471
- name: "Pypy"
7572
env_file: actions-pypy-38.yaml
7673
pattern: "not slow and not network and not single_cpu"
@@ -79,7 +76,6 @@ jobs:
7976
env_file: actions-310-numpydev.yaml
8077
pattern: "not slow and not network and not single_cpu"
8178
test_args: "-W error::DeprecationWarning -W error::FutureWarning"
82-
error_on_warnings: "0"
8379
exclude:
8480
- env_file: actions-38.yaml
8581
pyarrow_version: "8"
@@ -99,7 +95,6 @@ jobs:
9995
ENV_FILE: ci/deps/${{ matrix.env_file }}
10096
PATTERN: ${{ matrix.pattern }}
10197
EXTRA_APT: ${{ matrix.extra_apt || '' }}
102-
ERROR_ON_WARNINGS: ${{ matrix.error_on_warnings || '1' }}
10398
LANG: ${{ matrix.lang || '' }}
10499
LC_ALL: ${{ matrix.lc_all || '' }}
105100
PANDAS_DATA_MANAGER: ${{ matrix.pandas_data_manager || 'block' }}

ci/run_tests.sh

-7
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@ if [[ "$PATTERN" ]]; then
3030
PYTEST_CMD="$PYTEST_CMD -m \"$PATTERN\""
3131
fi
3232

33-
if [[ "$ERROR_ON_WARNINGS" == "1" ]]; then
34-
for pth in $(find pandas -name '*.py' -not -path "pandas/tests/*" | sed -e 's/\.py//g' -e 's/\/__init__//g' -e 's/\//./g');
35-
do
36-
PYTEST_CMD="$PYTEST_CMD -W error:::$pth"
37-
done
38-
fi
39-
4033
echo $PYTEST_CMD
4134
sh -c "$PYTEST_CMD"
4235

pandas/_testing/_warnings.py

+12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
nullcontext,
66
)
77
import re
8+
import sys
89
from typing import (
910
Generator,
1011
Literal,
@@ -163,6 +164,17 @@ def _assert_caught_no_extra_warnings(
163164

164165
for actual_warning in caught_warnings:
165166
if _is_unexpected_warning(actual_warning, expected_warning):
167+
# GH#38630 pytest.filterwarnings does not suppress these.
168+
if actual_warning.category == ResourceWarning:
169+
# GH 44732: Don't make the CI flaky by filtering SSL-related
170+
# ResourceWarning from dependencies
171+
if "unclosed <ssl.SSLSocket" in str(actual_warning.message):
172+
continue
173+
# GH 44844: Matplotlib leaves font files open during the entire process
174+
# upon import. Don't make CI flaky if ResourceWarning raised
175+
# due to these open files.
176+
if any("matplotlib" in mod for mod in sys.modules):
177+
continue
166178
extra_warnings.append(
167179
(
168180
actual_warning.category.__name__,

pandas/core/generic.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -4006,10 +4006,10 @@ class animal locomotion
40064006
40074007
Get values at several indexes
40084008
4009-
>>> df.xs(('mammal', 'dog'))
4010-
num_legs num_wings
4011-
locomotion
4012-
walks 4 0
4009+
>>> df.xs(('mammal', 'dog', 'walks'))
4010+
num_legs 4
4011+
num_wings 0
4012+
Name: (mammal, dog, walks), dtype: int64
40134013
40144014
Get values at specified index and level
40154015

pandas/io/sql.py

-27
Original file line numberDiff line numberDiff line change
@@ -632,36 +632,9 @@ def read_sql(
632632
>>> pd.read_sql('test_data', 'postgres:///db_name') # doctest:+SKIP
633633
634634
Apply date parsing to columns through the ``parse_dates`` argument
635-
636-
>>> pd.read_sql('SELECT int_column, date_column FROM test_data',
637-
... conn,
638-
... parse_dates=["date_column"])
639-
int_column date_column
640-
0 0 2012-10-11
641-
1 1 2010-12-11
642-
643635
The ``parse_dates`` argument calls ``pd.to_datetime`` on the provided columns.
644636
Custom argument values for applying ``pd.to_datetime`` on a column are specified
645637
via a dictionary format:
646-
1. Ignore errors while parsing the values of "date_column"
647-
648-
>>> pd.read_sql('SELECT int_column, date_column FROM test_data',
649-
... conn,
650-
... parse_dates={"date_column": {"errors": "ignore"}})
651-
int_column date_column
652-
0 0 2012-10-11
653-
1 1 2010-12-11
654-
655-
2. Apply a dayfirst date parsing order on the values of "date_column"
656-
657-
>>> pd.read_sql('SELECT int_column, date_column FROM test_data',
658-
... conn,
659-
... parse_dates={"date_column": {"dayfirst": True}})
660-
int_column date_column
661-
0 0 2012-11-10
662-
1 1 2010-11-12
663-
664-
3. Apply custom formatting when date parsing the values of "date_column"
665638
666639
>>> pd.read_sql('SELECT int_column, date_column FROM test_data',
667640
... conn,

pandas/tests/frame/test_query_eval.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,9 @@ def test_query_ea_dtypes(self, dtype):
13321332
# GH#50261
13331333
df = DataFrame({"a": Series([1, 2], dtype=dtype)})
13341334
ref = {2} # noqa:F841
1335-
result = df.query("a in @ref")
1335+
warning = RuntimeWarning if dtype == "Int64" and NUMEXPR_INSTALLED else None
1336+
with tm.assert_produces_warning(warning):
1337+
result = df.query("a in @ref")
13361338
expected = DataFrame({"a": Series([2], dtype=dtype, index=[1])})
13371339
tm.assert_frame_equal(result, expected)
13381340

pandas/tests/groupby/test_groupby.py

+3
Original file line numberDiff line numberDiff line change
@@ -2774,6 +2774,9 @@ def test_sum_of_booleans(n):
27742774
tm.assert_frame_equal(result, expected)
27752775

27762776

2777+
@pytest.mark.filterwarnings(
2778+
"ignore:invalid value encountered in remainder:RuntimeWarning"
2779+
)
27772780
@pytest.mark.parametrize("method", ["head", "tail", "nth", "first", "last"])
27782781
def test_groupby_method_drop_na(method):
27792782
# GH 21755

pandas/tests/groupby/test_nth.py

+3
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,9 @@ def test_nth_slices_with_column_axis(
789789
tm.assert_frame_equal(result, expected)
790790

791791

792+
@pytest.mark.filterwarnings(
793+
"ignore:invalid value encountered in remainder:RuntimeWarning"
794+
)
792795
def test_head_tail_dropna_true():
793796
# GH#45089
794797
df = DataFrame(

pandas/tests/io/pytables/test_retain_attributes.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from warnings import catch_warnings
2-
31
import pytest
42

53
from pandas._libs.tslibs import Timestamp
@@ -9,6 +7,7 @@
97
Series,
108
_testing as tm,
119
date_range,
10+
errors,
1211
read_hdf,
1312
)
1413
from pandas.tests.io.pytables.common import (
@@ -39,7 +38,7 @@ def test_retain_index_attributes(setup_path):
3938
)
4039

4140
# try to append a table with a different frequency
42-
with catch_warnings(record=True):
41+
with tm.assert_produces_warning(errors.AttributeConflictWarning):
4342
df2 = DataFrame(
4443
{
4544
"A": Series(
@@ -75,7 +74,7 @@ def test_retain_index_attributes(setup_path):
7574
def test_retain_index_attributes2(tmp_path, setup_path):
7675
path = tmp_path / setup_path
7776

78-
with catch_warnings(record=True):
77+
with tm.assert_produces_warning(errors.AttributeConflictWarning):
7978
df = DataFrame(
8079
{"A": Series(range(3), index=date_range("2000-1-1", periods=3, freq="H"))}
8180
)
@@ -93,7 +92,7 @@ def test_retain_index_attributes2(tmp_path, setup_path):
9392

9493
assert read_hdf(path, "data").index.name == "foo"
9594

96-
with catch_warnings(record=True):
95+
with tm.assert_produces_warning(errors.AttributeConflictWarning):
9796
idx2 = date_range("2001-1-1", periods=3, freq="H")
9897
idx2.name = "bar"
9998
df2 = DataFrame({"A": Series(range(3), index=idx2)})

pandas/tests/io/sas/test_byteswap.py

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def test_int_byteswap(read_offset, number, int_type, should_byteswap):
2929
_test(number, int_type, read_offset, should_byteswap)
3030

3131

32+
@pytest.mark.filterwarnings("ignore:overflow encountered:RuntimeWarning")
3233
@given(read_offset=st.integers(0, 11), number=st.floats())
3334
@pytest.mark.parametrize("float_type", [np.float32, np.float64])
3435
@pytest.mark.parametrize("should_byteswap", [True, False])

pandas/tests/series/test_arithmetic.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
ops,
3333
)
3434
from pandas.core.computation import expressions as expr
35+
from pandas.core.computation.check import NUMEXPR_INSTALLED
3536

3637

3738
@pytest.fixture(autouse=True, params=[0, 1000000], ids=["numexpr", "python"])
@@ -349,14 +350,21 @@ def test_add_list_to_masked_array(self, val, dtype):
349350
result = [1, None, val] + ser
350351
tm.assert_series_equal(result, expected)
351352

352-
def test_add_list_to_masked_array_boolean(self):
353+
def test_add_list_to_masked_array_boolean(self, request):
353354
# GH#22962
355+
warning = (
356+
UserWarning
357+
if request.node.callspec.id == "numexpr" and NUMEXPR_INSTALLED
358+
else None
359+
)
354360
ser = Series([True, None, False], dtype="boolean")
355-
result = ser + [True, None, True]
361+
with tm.assert_produces_warning(warning):
362+
result = ser + [True, None, True]
356363
expected = Series([True, None, True], dtype="boolean")
357364
tm.assert_series_equal(result, expected)
358365

359-
result = [True, None, True] + ser
366+
with tm.assert_produces_warning(warning):
367+
result = [True, None, True] + ser
360368
tm.assert_series_equal(result, expected)
361369

362370

pandas/tests/test_expressions.py

+3
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ def test_invalid(self):
199199
result = expr._can_use_numexpr(operator.add, "+", array, array2, "evaluate")
200200
assert result
201201

202+
@pytest.mark.filterwarnings(
203+
"ignore:invalid value encountered in true_divide:RuntimeWarning"
204+
)
202205
@pytest.mark.parametrize(
203206
"opname,op_str",
204207
[("add", "+"), ("sub", "-"), ("mul", "*"), ("truediv", "/"), ("pow", "**")],

pyproject.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,14 @@ doctest_optionflags = [
395395
"ELLIPSIS",
396396
]
397397
filterwarnings = [
398+
"error:::pandas",
398399
"error::ResourceWarning",
399400
"error::pytest.PytestUnraisableExceptionWarning",
400401
"ignore:.*ssl.SSLSocket:pytest.PytestUnraisableExceptionWarning",
401-
"ignore:unclosed <ssl.SSLSocket:ResourceWarning",
402+
"ignore:.*ssl.SSLSocket:ResourceWarning",
402403
"ignore::ResourceWarning:asyncio",
404+
# From plotting doctests
405+
"ignore:More than 20 figures have been opened:RuntimeWarning",
403406
# Will be fixed in numba 0.56: https://github.com/numba/numba/issues/7758
404407
"ignore:`np.MachAr` is deprecated:DeprecationWarning:numba",
405408
"ignore:.*urllib3:DeprecationWarning:botocore",

0 commit comments

Comments
 (0)