diff --git a/pandas/io/parquet.py b/pandas/io/parquet.py index 67e00dde5498b..cb66d1a422811 100644 --- a/pandas/io/parquet.py +++ b/pandas/io/parquet.py @@ -285,9 +285,6 @@ def write( **kwargs, ) -> None: self.validate_dataframe(df) - # thriftpy/protocol/compact.py:339: - # DeprecationWarning: tostring() is deprecated. - # Use tobytes() instead. if "partition_on" in kwargs and partition_cols is not None: raise ValueError( diff --git a/pandas/tests/frame/test_unary.py b/pandas/tests/frame/test_unary.py index 9caadd0998a26..9d38f621c0505 100644 --- a/pandas/tests/frame/test_unary.py +++ b/pandas/tests/frame/test_unary.py @@ -114,7 +114,10 @@ def test_pos_object(self, df): [ pytest.param( pd.DataFrame({"a": ["a", "b"]}), - marks=[pytest.mark.filterwarnings("ignore")], + # filterwarnings removable once min numpy version is 1.25 + marks=[ + pytest.mark.filterwarnings("ignore:Applying:DeprecationWarning") + ], ), ], ) diff --git a/pandas/tests/io/__init__.py b/pandas/tests/io/__init__.py index 15294fd0cabbc..e69de29bb2d1d 100644 --- a/pandas/tests/io/__init__.py +++ b/pandas/tests/io/__init__.py @@ -1,20 +0,0 @@ -import pytest - -pytestmark = [ - # fastparquet - pytest.mark.filterwarnings( - "ignore:PY_SSIZE_T_CLEAN will be required.*:DeprecationWarning" - ), - pytest.mark.filterwarnings( - r"ignore:`np\.bool` is a deprecated alias:DeprecationWarning" - ), - # xlrd - pytest.mark.filterwarnings( - "ignore:This method will be removed in future versions:DeprecationWarning" - ), - pytest.mark.filterwarnings( - "ignore:This method will be removed in future versions. " - r"Use 'tree.iter\(\)' or 'list\(tree.iter\(\)\)' instead." - ":PendingDeprecationWarning" - ), -] diff --git a/pandas/tests/io/excel/__init__.py b/pandas/tests/io/excel/__init__.py index 419761cbe1d6d..e69de29bb2d1d 100644 --- a/pandas/tests/io/excel/__init__.py +++ b/pandas/tests/io/excel/__init__.py @@ -1,12 +0,0 @@ -import pytest - -pytestmark = [ - pytest.mark.filterwarnings( - # Looks like tree.getiterator is deprecated in favor of tree.iter - "ignore:This method will be removed in future versions:" - "PendingDeprecationWarning" - ), - pytest.mark.filterwarnings( - "ignore:This method will be removed in future versions:DeprecationWarning" - ), -] diff --git a/pandas/tests/io/excel/test_readers.py b/pandas/tests/io/excel/test_readers.py index 430f8b4fd5d69..5899125ca2904 100644 --- a/pandas/tests/io/excel/test_readers.py +++ b/pandas/tests/io/excel/test_readers.py @@ -42,7 +42,6 @@ "openpyxl", marks=[ td.skip_if_no("openpyxl"), - pytest.mark.filterwarnings("ignore:.*html argument"), ], ), pytest.param( diff --git a/pandas/tests/io/pytables/__init__.py b/pandas/tests/io/pytables/__init__.py index 68c89658c137f..e69de29bb2d1d 100644 --- a/pandas/tests/io/pytables/__init__.py +++ b/pandas/tests/io/pytables/__init__.py @@ -1,14 +0,0 @@ -import pytest - -pytestmark = [ - # pytables https://github.com/PyTables/PyTables/issues/822 - pytest.mark.filterwarnings( - "ignore:a closed node found in the registry:UserWarning" - ), - pytest.mark.filterwarnings( - r"ignore:`np\.object` is a deprecated alias.*:DeprecationWarning" - ), - pytest.mark.filterwarnings( - r"ignore:`np\.bool` is a deprecated alias.*:DeprecationWarning" - ), -] diff --git a/pandas/tests/io/pytables/test_categorical.py b/pandas/tests/io/pytables/test_categorical.py index c70e49cfb0bde..7c2ab9b4f6ec0 100644 --- a/pandas/tests/io/pytables/test_categorical.py +++ b/pandas/tests/io/pytables/test_categorical.py @@ -16,10 +16,6 @@ pytestmark = [ pytest.mark.single_cpu, - # pytables https://github.com/PyTables/PyTables/issues/822 - pytest.mark.filterwarnings( - "ignore:a closed node found in the registry:UserWarning" - ), ] diff --git a/pandas/tests/io/pytables/test_subclass.py b/pandas/tests/io/pytables/test_subclass.py index 27843415f367e..823d2875c5417 100644 --- a/pandas/tests/io/pytables/test_subclass.py +++ b/pandas/tests/io/pytables/test_subclass.py @@ -13,9 +13,6 @@ ) pytest.importorskip("tables") -pytestmark = pytest.mark.filterwarnings( - "ignore:`np.object` is a deprecated alias:DeprecationWarning" -) class TestHDFStoreSubclass: diff --git a/pandas/tests/io/sas/test_sas7bdat.py b/pandas/tests/io/sas/test_sas7bdat.py index 325397d096745..348d2382976c3 100644 --- a/pandas/tests/io/sas/test_sas7bdat.py +++ b/pandas/tests/io/sas/test_sas7bdat.py @@ -38,7 +38,6 @@ def data_test_ix(request, dirpath): # https://github.com/cython/cython/issues/1720 -@pytest.mark.filterwarnings("ignore:can't resolve package:ImportWarning") class TestSAS7BDAT: @pytest.mark.slow def test_from_file(self, dirpath, data_test_ix): diff --git a/pandas/tests/io/test_common.py b/pandas/tests/io/test_common.py index 2172a4bf839fb..5ade1e0913804 100644 --- a/pandas/tests/io/test_common.py +++ b/pandas/tests/io/test_common.py @@ -50,7 +50,6 @@ def __fspath__(self): # https://github.com/cython/cython/issues/1720 -@pytest.mark.filterwarnings("ignore:can't resolve package:ImportWarning") class TestCommonIOCapabilities: data1 = """index,A,B,C,D foo,2,3,4,5 @@ -317,9 +316,6 @@ def test_read_expands_user_home_dir( ), ], ) - @pytest.mark.filterwarnings( # pytables np.object_ usage - "ignore:`np.object` is a deprecated alias:DeprecationWarning" - ) def test_read_fspath_all(self, reader, module, path, datapath): pytest.importorskip(module) path = datapath(*path) @@ -372,9 +368,6 @@ def test_write_fspath_all(self, writer_name, writer_kwargs, module): expected = f_path.read() assert result == expected - @pytest.mark.filterwarnings( # pytables np.object_ usage - "ignore:`np.object` is a deprecated alias:DeprecationWarning" - ) def test_write_fspath_hdf5(self): # Same test as write_fspath_all, except HDF5 files aren't # necessarily byte-for-byte identical for a given dataframe, so we'll diff --git a/pandas/tests/io/test_parquet.py b/pandas/tests/io/test_parquet.py index 398e2ccb09df2..12a3801ef1344 100644 --- a/pandas/tests/io/test_parquet.py +++ b/pandas/tests/io/test_parquet.py @@ -3,10 +3,7 @@ from io import BytesIO import os import pathlib -from warnings import ( - catch_warnings, - filterwarnings, -) +from warnings import catch_warnings import numpy as np import pytest @@ -40,13 +37,7 @@ _HAVE_PYARROW = False try: - with catch_warnings(): - # `np.bool` is a deprecated alias... - filterwarnings("ignore", "`np.bool`", category=DeprecationWarning) - # accessing pd.Int64Index in pd namespace - filterwarnings("ignore", ".*Int64Index.*", category=FutureWarning) - - import fastparquet + import fastparquet _HAVE_FASTPARQUET = True except ImportError: diff --git a/pandas/tests/io/test_pickle.py b/pandas/tests/io/test_pickle.py index 07a028a19d7f9..2c3617b7f3995 100644 --- a/pandas/tests/io/test_pickle.py +++ b/pandas/tests/io/test_pickle.py @@ -24,10 +24,7 @@ import shutil import tarfile import uuid -from warnings import ( - catch_warnings, - simplefilter, -) +from warnings import catch_warnings import zipfile import numpy as np @@ -132,49 +129,46 @@ def test_pickles(legacy_pickle): if not is_platform_little_endian(): pytest.skip("known failure on non-little endian") - with catch_warnings(record=True): - simplefilter("ignore") - - data = pd.read_pickle(legacy_pickle) - - for typ, dv in data.items(): - for dt, result in dv.items(): - expected = data[typ][dt] - - if typ == "series" and dt == "ts": - # GH 7748 - tm.assert_series_equal(result, expected) - assert result.index.freq == expected.index.freq - assert not result.index.freq.normalize - tm.assert_series_equal(result > 0, expected > 0) - - # GH 9291 - freq = result.index.freq - assert freq + Day(1) == Day(2) - - res = freq + pd.Timedelta(hours=1) - assert isinstance(res, pd.Timedelta) - assert res == pd.Timedelta(days=1, hours=1) - - res = freq + pd.Timedelta(nanoseconds=1) - assert isinstance(res, pd.Timedelta) - assert res == pd.Timedelta(days=1, nanoseconds=1) - elif typ == "index" and dt == "period": - tm.assert_index_equal(result, expected) - assert isinstance(result.freq, MonthEnd) - assert result.freq == MonthEnd() - assert result.freqstr == "M" - tm.assert_index_equal(result.shift(2), expected.shift(2)) - elif typ == "series" and dt in ("dt_tz", "cat"): - tm.assert_series_equal(result, expected) - elif typ == "frame" and dt in ( - "dt_mixed_tzs", - "cat_onecol", - "cat_and_float", - ): - tm.assert_frame_equal(result, expected) - else: - compare_element(result, expected, typ) + data = pd.read_pickle(legacy_pickle) + + for typ, dv in data.items(): + for dt, result in dv.items(): + expected = data[typ][dt] + + if typ == "series" and dt == "ts": + # GH 7748 + tm.assert_series_equal(result, expected) + assert result.index.freq == expected.index.freq + assert not result.index.freq.normalize + tm.assert_series_equal(result > 0, expected > 0) + + # GH 9291 + freq = result.index.freq + assert freq + Day(1) == Day(2) + + res = freq + pd.Timedelta(hours=1) + assert isinstance(res, pd.Timedelta) + assert res == pd.Timedelta(days=1, hours=1) + + res = freq + pd.Timedelta(nanoseconds=1) + assert isinstance(res, pd.Timedelta) + assert res == pd.Timedelta(days=1, nanoseconds=1) + elif typ == "index" and dt == "period": + tm.assert_index_equal(result, expected) + assert isinstance(result.freq, MonthEnd) + assert result.freq == MonthEnd() + assert result.freqstr == "M" + tm.assert_index_equal(result.shift(2), expected.shift(2)) + elif typ == "series" and dt in ("dt_tz", "cat"): + tm.assert_series_equal(result, expected) + elif typ == "frame" and dt in ( + "dt_mixed_tzs", + "cat_onecol", + "cat_and_float", + ): + tm.assert_frame_equal(result, expected) + else: + compare_element(result, expected, typ) def python_pickler(obj, path): diff --git a/pandas/tests/plotting/frame/test_frame_color.py b/pandas/tests/plotting/frame/test_frame_color.py index 925d9ca9e2fa2..2d8b3b14c8c68 100644 --- a/pandas/tests/plotting/frame/test_frame_color.py +++ b/pandas/tests/plotting/frame/test_frame_color.py @@ -1,6 +1,5 @@ """ Test cases for DataFrame.plot """ import re -import warnings import numpy as np import pytest @@ -18,23 +17,13 @@ @td.skip_if_no_mpl class TestDataFrameColor(TestPlotBase): - def test_mpl2_color_cycle_str(self): + @pytest.mark.parametrize( + "color", ["C0", "C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9"] + ) + def test_mpl2_color_cycle_str(self, color): # GH 15516 df = DataFrame(np.random.randn(10, 3), columns=["a", "b", "c"]) - colors = ["C0", "C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9"] - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter("always", "MatplotlibDeprecationWarning") - - for color in colors: - _check_plot_works(df.plot, color=color) - - # if warning is raised, check that it is the exact problematic one - # GH 36972 - if w: - match = "Support for uppercase single-letter colors is deprecated" - warning_message = str(w[0].message) - msg = "MatplotlibDeprecationWarning related to CN colors was raised" - assert match not in warning_message, msg + _check_plot_works(df.plot, color=color) def test_color_single_series_list(self): # GH 3486 diff --git a/pandas/tests/test_downstream.py b/pandas/tests/test_downstream.py index 5192b3d4cabf8..fea10075a0ace 100644 --- a/pandas/tests/test_downstream.py +++ b/pandas/tests/test_downstream.py @@ -18,11 +18,6 @@ ) import pandas._testing as tm -# xarray, fsspec, fastparquet all produce these -pytestmark = pytest.mark.filterwarnings( - "ignore:distutils Version classes are deprecated.*:DeprecationWarning" -) - def import_module(name): # we *only* want to skip if the module is truly not available @@ -148,12 +143,6 @@ def test_oo_optimized_datetime_index_unpickle(): @pytest.mark.network @tm.network -# Cython import warning -@pytest.mark.filterwarnings("ignore:can't:ImportWarning") -@pytest.mark.filterwarnings( - # patsy needs to update their imports - "ignore:Using or importing the ABCs from 'collections:DeprecationWarning" -) def test_statsmodels(): statsmodels = import_module("statsmodels") # noqa:F841 @@ -164,8 +153,6 @@ def test_statsmodels(): smf.ols("Lottery ~ Literacy + np.log(Pop1831)", data=df).fit() -# Cython import warning -@pytest.mark.filterwarnings("ignore:can't:ImportWarning") def test_scikit_learn(): sklearn = import_module("sklearn") # noqa:F841 @@ -180,10 +167,8 @@ def test_scikit_learn(): clf.predict(digits.data[-1:]) -# Cython import warning and traitlets @pytest.mark.network @tm.network -@pytest.mark.filterwarnings("ignore") def test_seaborn(): seaborn = import_module("seaborn") @@ -210,8 +195,6 @@ def test_pandas_datareader(): pandas_datareader.DataReader("F", "quandl", "2017-01-01", "2017-02-01") -# Cython import warning -@pytest.mark.filterwarnings("ignore:can't resolve:ImportWarning") def test_pyarrow(df): pyarrow = import_module("pyarrow") diff --git a/pandas/tests/util/test_show_versions.py b/pandas/tests/util/test_show_versions.py index 439971084fba8..8ff78cc073acf 100644 --- a/pandas/tests/util/test_show_versions.py +++ b/pandas/tests/util/test_show_versions.py @@ -2,8 +2,6 @@ import os import re -import pytest - from pandas.util._print_versions import ( _get_dependency_info, _get_sys_info, @@ -12,19 +10,6 @@ import pandas as pd -@pytest.mark.filterwarnings( - # openpyxl - "ignore:defusedxml.lxml is no longer supported:DeprecationWarning" -) -@pytest.mark.filterwarnings( - # html5lib - "ignore:Using or importing the ABCs from:DeprecationWarning" -) -@pytest.mark.filterwarnings( - # https://github.com/pandas-dev/pandas/issues/35252 - "ignore:Distutils:UserWarning" -) -@pytest.mark.filterwarnings("ignore:Setuptools is replacing distutils:UserWarning") def test_show_versions(tmpdir): # GH39701 as_json = os.path.join(tmpdir, "test_output.json") diff --git a/pandas/tests/window/__init__.py b/pandas/tests/window/__init__.py index 757bdfe755038..e69de29bb2d1d 100644 --- a/pandas/tests/window/__init__.py +++ b/pandas/tests/window/__init__.py @@ -1,8 +0,0 @@ -import pytest - -pytestmark = [ - # 2021-02-01 needed until numba updates their usage - pytest.mark.filterwarnings( - r"ignore:`np\.int` is a deprecated alias:DeprecationWarning" - ), -] diff --git a/pandas/util/_test_decorators.py b/pandas/util/_test_decorators.py index 59d5d6649c2a5..5bc55ee789fe6 100644 --- a/pandas/util/_test_decorators.py +++ b/pandas/util/_test_decorators.py @@ -32,7 +32,6 @@ def test_foo(): Callable, Generator, ) -import warnings import numpy as np import pytest @@ -67,41 +66,17 @@ def safe_import(mod_name: str, min_version: str | None = None): object The imported module if successful, or False """ - with warnings.catch_warnings(): - # Suppress warnings that we can't do anything about, - # e.g. from aiohttp - warnings.filterwarnings( - "ignore", - category=DeprecationWarning, - module="aiohttp", - message=".*decorator is deprecated since Python 3.8.*", - ) - - # fastparquet import accesses pd.Int64Index - warnings.filterwarnings( - "ignore", - category=FutureWarning, - module="fastparquet", - message=".*Int64Index.*", - ) - - warnings.filterwarnings( - "ignore", - category=DeprecationWarning, - message="distutils Version classes are deprecated.*", - ) - - try: - mod = __import__(mod_name) - except ImportError: + try: + mod = __import__(mod_name) + except ImportError: + return False + except SystemError: + # TODO: numba is incompatible with numpy 1.24+. + # Once that's fixed, this block should be removed. + if mod_name == "numba": return False - except SystemError: - # TODO: numba is incompatible with numpy 1.24+. - # Once that's fixed, this block should be removed. - if mod_name == "numba": - return False - else: - raise + else: + raise if not min_version: return mod diff --git a/pyproject.toml b/pyproject.toml index 9ef722d95c8b3..0308f86beb0d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -369,6 +369,15 @@ doctest_optionflags = [ filterwarnings = [ # 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", + "ignore:Setuptools is replacing distutils.:UserWarning:_distutils_hack", + # https://github.com/PyTables/PyTables/issues/822 + "ignore:a closed node found in the registry:UserWarning:tables", + "ignore:`np.object` is a deprecated:DeprecationWarning:tables", + "ignore:tostring:DeprecationWarning:tables", + "ignore:distutils Version classes are deprecated:DeprecationWarning:numexpr", + "ignore:distutils Version classes are deprecated:DeprecationWarning:fastparquet", + "ignore:distutils Version classes are deprecated:DeprecationWarning:fsspec", ] junit_family = "xunit2" markers = [