Skip to content

Commit b173e7b

Browse files
authored
TST: Cleanup more warning filtering (#50723)
* TST: Cleanup more warning filtering * Catch another futurewarning
1 parent 2c994c7 commit b173e7b

13 files changed

+17
-44
lines changed

pandas/conftest.py

-5
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@
9292
except zoneinfo.ZoneInfoNotFoundError: # type: ignore[attr-defined]
9393
zoneinfo = None
9494

95-
# Until https://github.com/numpy/numpy/issues/19078 is sorted out, just suppress
96-
suppress_npdev_promotion_warning = pytest.mark.filterwarnings(
97-
"ignore:Promotion of numbers and bools:FutureWarning"
98-
)
9995

10096
# ----------------------------------------------------------------
10197
# Configuration / Settings
@@ -171,7 +167,6 @@ def pytest_collection_modifyitems(items, config) -> None:
171167
# mark all tests in the pandas/tests/frame directory with "arraymanager"
172168
if "/frame/" in item.nodeid:
173169
item.add_marker(pytest.mark.arraymanager)
174-
item.add_marker(suppress_npdev_promotion_warning)
175170

176171
for (mark, kwd, skip_if_found, arg_name) in marks:
177172
if kwd in item.keywords:

pandas/core/nanops.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,9 @@ def get_median(x):
752752
return np.nan
753753
with warnings.catch_warnings():
754754
# Suppress RuntimeWarning about All-NaN slice
755-
warnings.filterwarnings("ignore", "All-NaN slice encountered")
755+
warnings.filterwarnings(
756+
"ignore", "All-NaN slice encountered", RuntimeWarning
757+
)
756758
res = np.nanmedian(x[mask])
757759
return res
758760

@@ -780,7 +782,9 @@ def get_median(x):
780782
# fastpath for the skipna case
781783
with warnings.catch_warnings():
782784
# Suppress RuntimeWarning about All-NaN slice
783-
warnings.filterwarnings("ignore", "All-NaN slice encountered")
785+
warnings.filterwarnings(
786+
"ignore", "All-NaN slice encountered", RuntimeWarning
787+
)
784788
res = np.nanmedian(values, axis)
785789

786790
else:

pandas/tests/arrays/floating/test_function.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
@pytest.mark.parametrize("ufunc", [np.abs, np.sign])
1111
# np.sign emits a warning with nans, <https://github.com/numpy/numpy/issues/15127>
12-
@pytest.mark.filterwarnings("ignore:invalid value encountered in sign")
12+
@pytest.mark.filterwarnings("ignore:invalid value encountered in sign:RuntimeWarning")
1313
def test_ufuncs_single(ufunc):
1414
a = pd.array([1, 2, -3, np.nan], dtype="Float64")
1515
result = ufunc(a)

pandas/tests/arrays/integer/test_function.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
@pytest.mark.parametrize("ufunc", [np.abs, np.sign])
1010
# np.sign emits a warning with nans, <https://github.com/numpy/numpy/issues/15127>
11-
@pytest.mark.filterwarnings("ignore:invalid value encountered in sign")
11+
@pytest.mark.filterwarnings("ignore:invalid value encountered in sign:RuntimeWarning")
1212
def test_ufuncs_single_int(ufunc):
1313
a = pd.array([1, 2, -3, np.nan])
1414
result = ufunc(a)

pandas/tests/io/excel/test_xlsxwriter.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import contextlib
2-
import warnings
32

43
import pytest
54

@@ -16,10 +15,7 @@
1615
def test_column_format(ext):
1716
# Test that column formats are applied to cells. Test for issue #9167.
1817
# Applicable to xlsxwriter only.
19-
with warnings.catch_warnings():
20-
# Ignore the openpyxl lxml warning.
21-
warnings.simplefilter("ignore")
22-
openpyxl = pytest.importorskip("openpyxl")
18+
openpyxl = pytest.importorskip("openpyxl")
2319

2420
with tm.ensure_clean(ext) as path:
2521
frame = DataFrame({"A": [123456, 123456], "B": [123456, 123456]})

pandas/tests/io/json/test_json_table_schema.py

-9
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,6 @@ def test_read_json_from_to_json_results(self):
260260
tm.assert_frame_equal(result1, df)
261261
tm.assert_frame_equal(result2, df)
262262

263-
@pytest.mark.filterwarnings(
264-
"ignore:an integer is required (got type float)*:DeprecationWarning"
265-
)
266263
def test_to_json(self, df_table):
267264
df = df_table
268265
df.index.name = "idx"
@@ -439,9 +436,6 @@ def test_to_json_categorical_index(self):
439436

440437
assert result == expected
441438

442-
@pytest.mark.filterwarnings(
443-
"ignore:an integer is required (got type float)*:DeprecationWarning"
444-
)
445439
def test_date_format_raises(self, df_table):
446440
msg = (
447441
"Trying to write with `orient='table'` and `date_format='epoch'`. Table "
@@ -785,9 +779,6 @@ def test_read_json_table_timezones_orient(self, idx, vals, recwarn):
785779
result = pd.read_json(out, orient="table")
786780
tm.assert_frame_equal(df, result)
787781

788-
@pytest.mark.filterwarnings(
789-
"ignore:an integer is required (got type float)*:DeprecationWarning"
790-
)
791782
def test_comprehensive(self):
792783
df = DataFrame(
793784
{

pandas/tests/io/json/test_pandas.py

-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ def assert_json_roundtrip_equal(result, expected, orient):
3232
tm.assert_frame_equal(result, expected)
3333

3434

35-
@pytest.mark.filterwarnings(
36-
"ignore:an integer is required (got type float)*:DeprecationWarning"
37-
)
3835
class TestPandasContainer:
3936
@pytest.fixture
4037
def categorical_frame(self):

pandas/tests/io/parser/common/test_read_errors.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ def test_open_file(request, all_parsers):
221221
file = Path(path)
222222
file.write_bytes(b"\xe4\na\n1")
223223

224-
# should not trigger a ResourceWarning
225-
warnings.simplefilter("always", category=ResourceWarning)
226224
with warnings.catch_warnings(record=True) as record:
225+
# should not trigger a ResourceWarning
226+
warnings.simplefilter("always", category=ResourceWarning)
227227
with pytest.raises(csv.Error, match="Could not determine delimiter"):
228228
parser.read_csv(file, sep=None, encoding_errors="replace")
229229
assert len(record) == 0, record[0].message

pandas/tests/io/pytables/test_append.py

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
pytestmark = pytest.mark.single_cpu
2727

2828

29-
@pytest.mark.filterwarnings("ignore:object name:tables.exceptions.NaturalNameWarning")
3029
def test_append(setup_path):
3130

3231
with ensure_clean_store(setup_path) as store:

pandas/tests/io/pytables/test_retain_attributes.py

-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ def test_retain_index_attributes(setup_path):
7373
store.append("df2", df3)
7474

7575

76-
@pytest.mark.filterwarnings(
77-
"ignore:\\nthe :pandas.io.pytables.AttributeConflictWarning"
78-
)
7976
def test_retain_index_attributes2(tmp_path, setup_path):
8077
path = tmp_path / setup_path
8178

pandas/tests/io/pytables/test_store.py

-10
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@
3131
)
3232

3333
_default_compressor = "blosc"
34-
ignore_natural_naming_warning = pytest.mark.filterwarnings(
35-
"ignore:object name:tables.exceptions.NaturalNameWarning"
36-
)
3734

3835
from pandas.io.pytables import (
3936
HDFStore,
@@ -154,7 +151,6 @@ def test_repr(setup_path):
154151
str(s)
155152

156153

157-
@pytest.mark.filterwarnings("ignore:object name:tables.exceptions.NaturalNameWarning")
158154
def test_contains(setup_path):
159155

160156
with ensure_clean_store(setup_path) as store:
@@ -598,9 +594,6 @@ def test_overwrite_node(setup_path):
598594
tm.assert_series_equal(store["a"], ts)
599595

600596

601-
@pytest.mark.filterwarnings(
602-
"ignore:\\nthe :pandas.io.pytables.AttributeConflictWarning"
603-
)
604597
def test_coordinates(setup_path):
605598
df = tm.makeTimeDataFrame()
606599

@@ -972,9 +965,6 @@ def test_columns_multiindex_modified(tmp_path, setup_path):
972965
assert cols2load_original == cols2load
973966

974967

975-
pytest.mark.filterwarnings("ignore:object name:tables.exceptions.NaturalNameWarning")
976-
977-
978968
def test_to_hdf_with_object_column_names(tmp_path, setup_path):
979969
# GH9057
980970

pandas/tests/io/test_sql.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,12 @@ def psql_insert_copy(table, conn, keys, data_iter):
665665

666666
def test_execute_typeerror(sqlite_iris_engine):
667667
with pytest.raises(TypeError, match="pandas.io.sql.execute requires a connection"):
668-
sql.execute("select * from iris", sqlite_iris_engine)
668+
with tm.assert_produces_warning(
669+
FutureWarning,
670+
match="`pandas.io.sql.execute` is deprecated and "
671+
"will be removed in the future version.",
672+
):
673+
sql.execute("select * from iris", sqlite_iris_engine)
669674

670675

671676
def test_execute_deprecated(sqlite_buildin_iris):

pandas/tests/window/test_win_type.py

-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ def test_constructor_with_win_type_invalid(frame_or_series):
110110

111111

112112
@td.skip_if_no_scipy
113-
@pytest.mark.filterwarnings("ignore:can't resolve:ImportWarning")
114113
def test_window_with_args(step):
115114
# make sure that we are aggregating window functions correctly with arg
116115
r = Series(np.random.randn(100)).rolling(

0 commit comments

Comments
 (0)