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 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/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..c4ab708f33978 100644 --- a/pandas/tests/plotting/frame/test_frame.py +++ b/pandas/tests/plotting/frame/test_frame.py @@ -52,6 +52,15 @@ mpl = pytest.importorskip("matplotlib") plt = pytest.importorskip("matplotlib.pyplot") +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: @pytest.mark.slow diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index eb1b4f7d85a68..779e539b3afba 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -40,6 +40,15 @@ 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.mark.filterwarnings( + "ignore:invalid value encountered in scalar multiply:RuntimeWarning" + ), +] + @pytest.fixture def ts(): 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..5c836951961f2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -457,6 +457,10 @@ filterwarnings = [ "error:::pandas", "error::ResourceWarning", "error::pytest.PytestUnraisableExceptionWarning", + "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",