From 969e0a24d160dd64c89160ded2506f3551a72a25 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Tue, 29 Jul 2025 10:59:48 -0700 Subject: [PATCH 1/6] Error on pytest.PytestWarning --- pandas/tests/arrays/test_datetimes.py | 2 +- pandas/tests/dtypes/test_dtypes.py | 8 ++++++-- pandas/tests/frame/test_ufunc.py | 2 +- pandas/tests/indexes/numeric/test_indexing.py | 4 ++-- pandas/tests/indexes/test_base.py | 4 ++-- pandas/tests/indexing/multiindex/test_getitem.py | 8 ++++++-- pandas/tests/io/json/test_normalize.py | 2 +- pandas/tests/io/parser/common/test_chunksize.py | 2 +- pandas/tests/series/test_ufunc.py | 2 +- pyproject.toml | 1 + 10 files changed, 22 insertions(+), 13 deletions(-) diff --git a/pandas/tests/arrays/test_datetimes.py b/pandas/tests/arrays/test_datetimes.py index 87505b1b22fc4..944bd84145f05 100644 --- a/pandas/tests/arrays/test_datetimes.py +++ b/pandas/tests/arrays/test_datetimes.py @@ -100,7 +100,7 @@ def test_simple_new_requires_match(self, unit): assert dta.dtype == dtype wrong = DatetimeTZDtype("ns", "UTC") - with pytest.raises(AssertionError, match=""): + with pytest.raises(AssertionError, match="^$"): DatetimeArray._simple_new(arr, dtype=wrong) def test_std_non_nano(self, unit): diff --git a/pandas/tests/dtypes/test_dtypes.py b/pandas/tests/dtypes/test_dtypes.py index 621217a8c9317..c9d3f83ce9237 100644 --- a/pandas/tests/dtypes/test_dtypes.py +++ b/pandas/tests/dtypes/test_dtypes.py @@ -249,10 +249,14 @@ def test_alias_to_unit_raises(self): def test_alias_to_unit_bad_alias_raises(self): # 23990 - with pytest.raises(TypeError, match=""): + with pytest.raises( + TypeError, match="Cannot construct a 'DatetimeTZDtype' from" + ): DatetimeTZDtype("this is a bad string") - with pytest.raises(TypeError, match=""): + with pytest.raises( + TypeError, match="Cannot construct a 'DatetimeTZDtype' from" + ): DatetimeTZDtype("datetime64[ns, US/NotATZ]") def test_hash_vs_equality(self, dtype): diff --git a/pandas/tests/frame/test_ufunc.py b/pandas/tests/frame/test_ufunc.py index 092e65dd4b431..ce66d448a0d40 100644 --- a/pandas/tests/frame/test_ufunc.py +++ b/pandas/tests/frame/test_ufunc.py @@ -191,7 +191,7 @@ def test_unary_accumulate_axis(): def test_frame_outer_disallowed(): df = pd.DataFrame({"A": [1, 2]}) - with pytest.raises(NotImplementedError, match=""): + with pytest.raises(NotImplementedError, match="^$"): # deprecation enforced in 2.0 np.subtract.outer(df, df) diff --git a/pandas/tests/indexes/numeric/test_indexing.py b/pandas/tests/indexes/numeric/test_indexing.py index 3c1b98d57b2a0..b29f783203177 100644 --- a/pandas/tests/indexes/numeric/test_indexing.py +++ b/pandas/tests/indexes/numeric/test_indexing.py @@ -585,10 +585,10 @@ def test_slice_locs_na(self): def test_slice_locs_na_raises(self): index = Index([np.nan, 1, 2]) - with pytest.raises(KeyError, match=""): + with pytest.raises(KeyError, match="1.5"): index.slice_locs(start=1.5) - with pytest.raises(KeyError, match=""): + with pytest.raises(KeyError, match="1.5"): index.slice_locs(end=1.5) diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index e734878e6a102..985ed880e7998 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -712,7 +712,7 @@ def test_drop_by_str_label(self, index): ) @pytest.mark.parametrize("keys", [["foo", "bar"], ["1", "bar"]]) def test_drop_by_str_label_raises_missing_keys(self, index, keys): - with pytest.raises(KeyError, match=""): + with pytest.raises(KeyError, match=".* not found in axis"): index.drop(keys) @pytest.mark.parametrize( @@ -741,7 +741,7 @@ def test_drop_by_numeric_label_loc(self): def test_drop_by_numeric_label_raises_missing_keys(self): index = Index([1, 2, 3]) - with pytest.raises(KeyError, match=""): + with pytest.raises(KeyError, match=re.escape("[4] not found in axis")): index.drop([3, 4]) @pytest.mark.parametrize( diff --git a/pandas/tests/indexing/multiindex/test_getitem.py b/pandas/tests/indexing/multiindex/test_getitem.py index b86e233110e88..41e90fca281e1 100644 --- a/pandas/tests/indexing/multiindex/test_getitem.py +++ b/pandas/tests/indexing/multiindex/test_getitem.py @@ -89,8 +89,12 @@ def test_series_getitem_returns_scalar( (lambda s: s[(2000, 3, 4)], KeyError, r"^\(2000, 3, 4\)$"), (lambda s: s.loc[(2000, 3, 4)], KeyError, r"^\(2000, 3, 4\)$"), (lambda s: s.loc[(2000, 3, 4, 5)], IndexingError, "Too many indexers"), - (lambda s: s.__getitem__(len(s)), KeyError, ""), # match should include len(s) - (lambda s: s[len(s)], KeyError, ""), # match should include len(s) + ( + lambda s: s.__getitem__(len(s)), + KeyError, + "100", + ), # match should include len(s) + (lambda s: s[len(s)], KeyError, "100"), # match should include len(s) ( lambda s: s.iloc[len(s)], IndexError, diff --git a/pandas/tests/io/json/test_normalize.py b/pandas/tests/io/json/test_normalize.py index fdbfbd004617e..cde0a7a378cff 100644 --- a/pandas/tests/io/json/test_normalize.py +++ b/pandas/tests/io/json/test_normalize.py @@ -172,7 +172,7 @@ def test_empty_array(self): ) def test_accepted_input(self, data, record_path, exception_type): if exception_type is not None: - with pytest.raises(exception_type, match=""): + with pytest.raises(exception_type, match="^$"): json_normalize(data, record_path=record_path) else: result = json_normalize(data, record_path=record_path) diff --git a/pandas/tests/io/parser/common/test_chunksize.py b/pandas/tests/io/parser/common/test_chunksize.py index 65ad7273666e5..75ec96409bdd0 100644 --- a/pandas/tests/io/parser/common/test_chunksize.py +++ b/pandas/tests/io/parser/common/test_chunksize.py @@ -129,7 +129,7 @@ def test_read_chunksize_and_nrows_changing_size(all_parsers): tm.assert_frame_equal(reader.get_chunk(size=2), expected.iloc[:2]) tm.assert_frame_equal(reader.get_chunk(size=4), expected.iloc[2:5]) - with pytest.raises(StopIteration, match=""): + with pytest.raises(StopIteration, match="^$"): reader.get_chunk(size=3) diff --git a/pandas/tests/series/test_ufunc.py b/pandas/tests/series/test_ufunc.py index a5976bb2518c9..5faacbb5559a9 100644 --- a/pandas/tests/series/test_ufunc.py +++ b/pandas/tests/series/test_ufunc.py @@ -414,7 +414,7 @@ def test_outer(): ser = pd.Series([1, 2, 3]) obj = np.array([1, 2, 3]) - with pytest.raises(NotImplementedError, match=""): + with pytest.raises(NotImplementedError, match="^$"): np.subtract.outer(ser, obj) diff --git a/pyproject.toml b/pyproject.toml index 0dd5c65413936..228ba5fdc6a55 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -457,6 +457,7 @@ filterwarnings = [ "error:::pandas", "error::ResourceWarning", "error::pytest.PytestUnraisableExceptionWarning", + "error::pytest.PytestWarning", # TODO(PY311-minimum): Specify EncodingWarning # Ignore 3rd party EncodingWarning but raise on pandas' "ignore:.*encoding.* argument not specified", From 93d804ae4a2e44722b55de600bb526f9a16b6a06 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Tue, 29 Jul 2025 11:07:36 -0700 Subject: [PATCH 2/6] ignore runtimewarning in plotting tests --- pandas/tests/io/test_sql.py | 2 +- pandas/tests/plotting/frame/test_frame.py | 4 ++++ pandas/tests/plotting/test_series.py | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pandas/tests/io/test_sql.py b/pandas/tests/io/test_sql.py index 6f4c1602a5e64..f8638ea104933 100644 --- a/pandas/tests/io/test_sql.py +++ b/pandas/tests/io/test_sql.py @@ -2226,7 +2226,7 @@ def test_api_chunksize_read(conn, request): # reading the query in chunks with read_sql_query if conn_name == "sqlite_buildin": - with pytest.raises(NotImplementedError, match=""): + with pytest.raises(NotImplementedError, match="^$"): sql.read_sql_table("test_chunksize", conn, chunksize=5) else: res3 = DataFrame() diff --git a/pandas/tests/plotting/frame/test_frame.py b/pandas/tests/plotting/frame/test_frame.py index 3f274a336ad44..f944609471a42 100644 --- a/pandas/tests/plotting/frame/test_frame.py +++ b/pandas/tests/plotting/frame/test_frame.py @@ -52,6 +52,10 @@ mpl = pytest.importorskip("matplotlib") plt = pytest.importorskip("matplotlib.pyplot") +pytestmark = pytest.mark.filterwarnings( + "ignore:divide by zero encountered in scalar divide:RuntimeWarning" +) + class TestDataFramePlots: @pytest.mark.slow diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index eb1b4f7d85a68..757b380559627 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -40,6 +40,10 @@ from pandas.plotting._matplotlib.converter import DatetimeConverter from pandas.plotting._matplotlib.style import get_standard_colors +pytestmark = pytest.mark.filterwarnings( + "ignore:divide by zero encountered in scalar divide:RuntimeWarning" +) + @pytest.fixture def ts(): From 769d02faf1deb8a724e63c3bb64a24616b04871a Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Tue, 29 Jul 2025 11:17:24 -0700 Subject: [PATCH 3/6] Ignore PytestAssertRewriteWarning for hypothesis --- pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 228ba5fdc6a55..2fb519e590d38 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -458,6 +458,8 @@ filterwarnings = [ "error::ResourceWarning", "error::pytest.PytestUnraisableExceptionWarning", "error::pytest.PytestWarning", + # e.g. Module already imported so cannot be rewritten; _hypothesis_globals + "ignore::pytest.PytestAssertRewriteWarning", # TODO(PY311-minimum): Specify EncodingWarning # Ignore 3rd party EncodingWarning but raise on pandas' "ignore:.*encoding.* argument not specified", From 91e6c86a24c794653ac65bd4dc85de8cbcf28672 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Tue, 29 Jul 2025 11:25:47 -0700 Subject: [PATCH 4/6] Clarify past no future infer strings --- .github/workflows/unit-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 412f27cba9c4f..7bee8474d4db5 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -71,7 +71,7 @@ jobs: # It will be temporarily activated during tests with locale.setlocale extra_loc: "zh_CN" platform: ubuntu-24.04 - - name: "Past no infer strings" + - name: "PANDAS_FUTURE_INFER_STRING=0" env_file: actions-312.yaml pandas_future_infer_string: "0" platform: ubuntu-24.04 From e42d2b03f9643bd846ecfcc58844f4e9918d3127 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Tue, 29 Jul 2025 11:59:29 -0700 Subject: [PATCH 5/6] Add pytest.PytestCacheWarning --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 2fb519e590d38..5c836951961f2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -460,6 +460,7 @@ filterwarnings = [ "error::pytest.PytestWarning", # e.g. Module already imported so cannot be rewritten; _hypothesis_globals "ignore::pytest.PytestAssertRewriteWarning", + "ignore::pytest.PytestCacheWarning", # TODO(PY311-minimum): Specify EncodingWarning # Ignore 3rd party EncodingWarning but raise on pandas' "ignore:.*encoding.* argument not specified", From 894162959b2ad8a76021eed5e4ec0b7dd1d29f23 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Tue, 29 Jul 2025 13:58:58 -0700 Subject: [PATCH 6/6] Ignore another runtimewarning --- pandas/tests/plotting/frame/test_frame.py | 11 ++++++++--- pandas/tests/plotting/test_series.py | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/pandas/tests/plotting/frame/test_frame.py b/pandas/tests/plotting/frame/test_frame.py index f944609471a42..c4ab708f33978 100644 --- a/pandas/tests/plotting/frame/test_frame.py +++ b/pandas/tests/plotting/frame/test_frame.py @@ -52,9 +52,14 @@ mpl = pytest.importorskip("matplotlib") plt = pytest.importorskip("matplotlib.pyplot") -pytestmark = pytest.mark.filterwarnings( - "ignore:divide by zero encountered in scalar divide:RuntimeWarning" -) +pytestmark = [ + pytest.mark.filterwarnings( + "ignore:divide by zero encountered in scalar divide:RuntimeWarning" + ), + pytest.mark.filterwarnings( + "ignore:invalid value encountered in scalar multiply:RuntimeWarning" + ), +] class TestDataFramePlots: diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index 757b380559627..779e539b3afba 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -40,9 +40,14 @@ from pandas.plotting._matplotlib.converter import DatetimeConverter from pandas.plotting._matplotlib.style import get_standard_colors -pytestmark = pytest.mark.filterwarnings( - "ignore:divide by zero encountered in scalar divide:RuntimeWarning" -) +pytestmark = [ + pytest.mark.filterwarnings( + "ignore:divide by zero encountered in scalar divide:RuntimeWarning" + ), + pytest.mark.filterwarnings( + "ignore:invalid value encountered in scalar multiply:RuntimeWarning" + ), +] @pytest.fixture