Skip to content

TST: Cleanup more warning filtering #50723

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 3 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 0 additions & 5 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@
except zoneinfo.ZoneInfoNotFoundError: # type: ignore[attr-defined]
zoneinfo = None

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

# ----------------------------------------------------------------
# Configuration / Settings
Expand Down Expand Up @@ -171,7 +167,6 @@ def pytest_collection_modifyitems(items, config) -> None:
# mark all tests in the pandas/tests/frame directory with "arraymanager"
if "/frame/" in item.nodeid:
item.add_marker(pytest.mark.arraymanager)
item.add_marker(suppress_npdev_promotion_warning)

for (mark, kwd, skip_if_found, arg_name) in marks:
if kwd in item.keywords:
Expand Down
8 changes: 6 additions & 2 deletions pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,9 @@ def get_median(x):
return np.nan
with warnings.catch_warnings():
# Suppress RuntimeWarning about All-NaN slice
warnings.filterwarnings("ignore", "All-NaN slice encountered")
warnings.filterwarnings(
"ignore", "All-NaN slice encountered", RuntimeWarning
)
res = np.nanmedian(x[mask])
return res

Expand Down Expand Up @@ -780,7 +782,9 @@ def get_median(x):
# fastpath for the skipna case
with warnings.catch_warnings():
# Suppress RuntimeWarning about All-NaN slice
warnings.filterwarnings("ignore", "All-NaN slice encountered")
warnings.filterwarnings(
"ignore", "All-NaN slice encountered", RuntimeWarning
)
res = np.nanmedian(values, axis)

else:
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/arrays/floating/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@pytest.mark.parametrize("ufunc", [np.abs, np.sign])
# np.sign emits a warning with nans, <https://github.com/numpy/numpy/issues/15127>
@pytest.mark.filterwarnings("ignore:invalid value encountered in sign")
@pytest.mark.filterwarnings("ignore:invalid value encountered in sign:RuntimeWarning")
def test_ufuncs_single(ufunc):
a = pd.array([1, 2, -3, np.nan], dtype="Float64")
result = ufunc(a)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/arrays/integer/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@pytest.mark.parametrize("ufunc", [np.abs, np.sign])
# np.sign emits a warning with nans, <https://github.com/numpy/numpy/issues/15127>
@pytest.mark.filterwarnings("ignore:invalid value encountered in sign")
@pytest.mark.filterwarnings("ignore:invalid value encountered in sign:RuntimeWarning")
def test_ufuncs_single_int(ufunc):
a = pd.array([1, 2, -3, np.nan])
result = ufunc(a)
Expand Down
6 changes: 1 addition & 5 deletions pandas/tests/io/excel/test_xlsxwriter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import contextlib
import warnings

import pytest

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

with tm.ensure_clean(ext) as path:
frame = DataFrame({"A": [123456, 123456], "B": [123456, 123456]})
Expand Down
9 changes: 0 additions & 9 deletions pandas/tests/io/json/test_json_table_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,6 @@ def test_read_json_from_to_json_results(self):
tm.assert_frame_equal(result1, df)
tm.assert_frame_equal(result2, df)

@pytest.mark.filterwarnings(
"ignore:an integer is required (got type float)*:DeprecationWarning"
)
def test_to_json(self, df_table):
df = df_table
df.index.name = "idx"
Expand Down Expand Up @@ -439,9 +436,6 @@ def test_to_json_categorical_index(self):

assert result == expected

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

@pytest.mark.filterwarnings(
"ignore:an integer is required (got type float)*:DeprecationWarning"
)
def test_comprehensive(self):
df = DataFrame(
{
Expand Down
3 changes: 0 additions & 3 deletions pandas/tests/io/json/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ def assert_json_roundtrip_equal(result, expected, orient):
tm.assert_frame_equal(result, expected)


@pytest.mark.filterwarnings(
"ignore:an integer is required (got type float)*:DeprecationWarning"
)
class TestPandasContainer:
@pytest.fixture
def categorical_frame(self):
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/io/parser/common/test_read_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ def test_open_file(request, all_parsers):
file = Path(path)
file.write_bytes(b"\xe4\na\n1")

# should not trigger a ResourceWarning
warnings.simplefilter("always", category=ResourceWarning)
with warnings.catch_warnings(record=True) as record:
# should not trigger a ResourceWarning
warnings.simplefilter("always", category=ResourceWarning)
with pytest.raises(csv.Error, match="Could not determine delimiter"):
parser.read_csv(file, sep=None, encoding_errors="replace")
assert len(record) == 0, record[0].message
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/io/pytables/test_append.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
pytestmark = pytest.mark.single_cpu


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

with ensure_clean_store(setup_path) as store:
Expand Down
3 changes: 0 additions & 3 deletions pandas/tests/io/pytables/test_retain_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ def test_retain_index_attributes(setup_path):
store.append("df2", df3)


@pytest.mark.filterwarnings(
"ignore:\\nthe :pandas.io.pytables.AttributeConflictWarning"
)
def test_retain_index_attributes2(tmp_path, setup_path):
path = tmp_path / setup_path

Expand Down
10 changes: 0 additions & 10 deletions pandas/tests/io/pytables/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
)

_default_compressor = "blosc"
ignore_natural_naming_warning = pytest.mark.filterwarnings(
"ignore:object name:tables.exceptions.NaturalNameWarning"
)

from pandas.io.pytables import (
HDFStore,
Expand Down Expand Up @@ -154,7 +151,6 @@ def test_repr(setup_path):
str(s)


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

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


@pytest.mark.filterwarnings(
"ignore:\\nthe :pandas.io.pytables.AttributeConflictWarning"
)
def test_coordinates(setup_path):
df = tm.makeTimeDataFrame()

Expand Down Expand Up @@ -972,9 +965,6 @@ def test_columns_multiindex_modified(tmp_path, setup_path):
assert cols2load_original == cols2load


pytest.mark.filterwarnings("ignore:object name:tables.exceptions.NaturalNameWarning")


def test_to_hdf_with_object_column_names(tmp_path, setup_path):
# GH9057

Expand Down
7 changes: 6 additions & 1 deletion pandas/tests/io/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,12 @@ def psql_insert_copy(table, conn, keys, data_iter):

def test_execute_typeerror(sqlite_iris_engine):
with pytest.raises(TypeError, match="pandas.io.sql.execute requires a connection"):
sql.execute("select * from iris", sqlite_iris_engine)
with tm.assert_produces_warning(
FutureWarning,
match="`pandas.io.sql.execute` is deprecated and "
"will be removed in the future version.",
):
sql.execute("select * from iris", sqlite_iris_engine)


def test_execute_deprecated(sqlite_buildin_iris):
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/window/test_win_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ def test_constructor_with_win_type_invalid(frame_or_series):


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