diff --git a/doc/source/user_guide/10min.rst b/doc/source/user_guide/10min.rst index e9f1a073d77ef..c8e67710c85a9 100644 --- a/doc/source/user_guide/10min.rst +++ b/doc/source/user_guide/10min.rst @@ -763,14 +763,12 @@ Parquet Writing to a Parquet file: .. ipython:: python - :okwarning: df.to_parquet("foo.parquet") Reading from a Parquet file Store using :func:`read_parquet`: .. ipython:: python - :okwarning: pd.read_parquet("foo.parquet") diff --git a/doc/source/user_guide/io.rst b/doc/source/user_guide/io.rst index cebe58a4da62e..73ec09cdd12f1 100644 --- a/doc/source/user_guide/io.rst +++ b/doc/source/user_guide/io.rst @@ -2247,7 +2247,6 @@ For line-delimited json files, pandas can also return an iterator which reads in Line-limited json can also be read using the pyarrow reader by specifying ``engine="pyarrow"``. .. ipython:: python - :okwarning: from io import BytesIO df = pd.read_json(BytesIO(jsonl.encode()), lines=True, engine="pyarrow") @@ -5372,7 +5371,6 @@ See the documentation for `pyarrow `__ an Write to a parquet file. .. ipython:: python - :okwarning: df.to_parquet("example_pa.parquet", engine="pyarrow") df.to_parquet("example_fp.parquet", engine="fastparquet") @@ -5380,7 +5378,6 @@ Write to a parquet file. Read from a parquet file. .. ipython:: python - :okwarning: result = pd.read_parquet("example_fp.parquet", engine="fastparquet") result = pd.read_parquet("example_pa.parquet", engine="pyarrow") @@ -5390,7 +5387,6 @@ Read from a parquet file. By setting the ``dtype_backend`` argument you can control the default dtypes used for the resulting DataFrame. .. ipython:: python - :okwarning: result = pd.read_parquet("example_pa.parquet", engine="pyarrow", dtype_backend="pyarrow") @@ -5404,7 +5400,6 @@ By setting the ``dtype_backend`` argument you can control the default dtypes use Read only certain columns of a parquet file. .. ipython:: python - :okwarning: result = pd.read_parquet( "example_fp.parquet", @@ -5433,7 +5428,6 @@ Serializing a ``DataFrame`` to parquet may include the implicit index as one or more columns in the output file. Thus, this code: .. ipython:: python - :okwarning: df = pd.DataFrame({"a": [1, 2], "b": [3, 4]}) df.to_parquet("test.parquet", engine="pyarrow") @@ -5450,7 +5444,6 @@ If you want to omit a dataframe's indexes when writing, pass ``index=False`` to :func:`~pandas.DataFrame.to_parquet`: .. ipython:: python - :okwarning: df.to_parquet("test.parquet", index=False) @@ -5473,7 +5466,6 @@ Partitioning Parquet files Parquet supports partitioning of data based on the values of one or more columns. .. ipython:: python - :okwarning: df = pd.DataFrame({"a": [0, 0, 1, 1], "b": [0, 1, 0, 1]}) df.to_parquet(path="test", engine="pyarrow", partition_cols=["a"], compression=None) @@ -5539,14 +5531,12 @@ ORC format, :func:`~pandas.read_orc` and :func:`~pandas.DataFrame.to_orc`. This Write to an orc file. .. ipython:: python - :okwarning: df.to_orc("example_pa.orc", engine="pyarrow") Read from an orc file. .. ipython:: python - :okwarning: result = pd.read_orc("example_pa.orc") @@ -5555,7 +5545,6 @@ Read from an orc file. Read only certain columns of an orc file. .. ipython:: python - :okwarning: result = pd.read_orc( "example_pa.orc", diff --git a/doc/source/user_guide/pyarrow.rst b/doc/source/user_guide/pyarrow.rst index 9012c7b591f34..61b383afb7c43 100644 --- a/doc/source/user_guide/pyarrow.rst +++ b/doc/source/user_guide/pyarrow.rst @@ -104,7 +104,6 @@ To convert a :external+pyarrow:py:class:`pyarrow.Table` to a :class:`DataFrame`, :external+pyarrow:py:meth:`pyarrow.Table.to_pandas` method with ``types_mapper=pd.ArrowDtype``. .. ipython:: python - :okwarning: table = pa.table([pa.array([1, 2, 3], type=pa.int64())], names=["a"]) @@ -165,7 +164,6 @@ functions provide an ``engine`` keyword that can dispatch to PyArrow to accelera * :func:`read_feather` .. ipython:: python - :okwarning: import io data = io.StringIO("""a,b,c @@ -180,7 +178,6 @@ PyArrow-backed data by specifying the parameter ``dtype_backend="pyarrow"``. A r ``engine="pyarrow"`` to necessarily return PyArrow-backed data. .. ipython:: python - :okwarning: import io data = io.StringIO("""a,b,c,d,e,f,g,h,i diff --git a/doc/source/user_guide/scale.rst b/doc/source/user_guide/scale.rst index 7b89b25f6ea38..b262de5d71439 100644 --- a/doc/source/user_guide/scale.rst +++ b/doc/source/user_guide/scale.rst @@ -51,7 +51,6 @@ To load the columns we want, we have two options. Option 1 loads in all the data and then filters to what we need. .. ipython:: python - :okwarning: columns = ["id_0", "name_0", "x_0", "y_0"] @@ -60,7 +59,6 @@ Option 1 loads in all the data and then filters to what we need. Option 2 only loads the columns we request. .. ipython:: python - :okwarning: pd.read_parquet("timeseries_wide.parquet", columns=columns) @@ -202,7 +200,6 @@ counts up to this point. As long as each individual file fits in memory, this wi work for arbitrary-sized datasets. .. ipython:: python - :okwarning: %%time files = pathlib.Path("data/timeseries/").glob("ts*.parquet") diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 07cc4aeed1272..be63da09846c8 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -152,7 +152,6 @@ When this keyword is set to ``"pyarrow"``, then these functions will return pyar * :meth:`Series.convert_dtypes` .. ipython:: python - :okwarning: import io data = io.StringIO("""a,b,c,d,e,f,g,h,i diff --git a/pandas/core/frame.py b/pandas/core/frame.py index f37be37f37693..49a051151d76c 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -697,7 +697,7 @@ def __init__( "is deprecated and will raise in a future version. " "Use public APIs instead.", DeprecationWarning, - stacklevel=find_stack_level(), + stacklevel=1, # bump to 2 once pyarrow 15.0 is released with fix ) if using_copy_on_write(): diff --git a/pandas/core/series.py b/pandas/core/series.py index 88d3616423155..413d29a78bc98 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -407,7 +407,7 @@ def __init__( "is deprecated and will raise in a future version. " "Use public APIs instead.", DeprecationWarning, - stacklevel=find_stack_level(), + stacklevel=2, ) if using_copy_on_write(): data = data.copy(deep=False) @@ -446,7 +446,7 @@ def __init__( "is deprecated and will raise in a future version. " "Use public APIs instead.", DeprecationWarning, - stacklevel=find_stack_level(), + stacklevel=2, ) if copy: @@ -465,7 +465,7 @@ def __init__( "is deprecated and will raise in a future version. " "Use public APIs instead.", DeprecationWarning, - stacklevel=find_stack_level(), + stacklevel=2, ) name = ibase.maybe_extract_name(name, data, type(self)) @@ -539,7 +539,7 @@ def __init__( "is deprecated and will raise in a future version. " "Use public APIs instead.", DeprecationWarning, - stacklevel=find_stack_level(), + stacklevel=2, ) allow_mgr = True diff --git a/pandas/tests/arrays/interval/test_interval.py b/pandas/tests/arrays/interval/test_interval.py index e772e4fba6c01..024721896cc58 100644 --- a/pandas/tests/arrays/interval/test_interval.py +++ b/pandas/tests/arrays/interval/test_interval.py @@ -309,6 +309,9 @@ def test_arrow_array_missing(): assert result.storage.equals(expected) +@pytest.mark.filterwarnings( + "ignore:Passing a BlockManager to DataFrame:DeprecationWarning" +) @pytest.mark.parametrize( "breaks", [[0.0, 1.0, 2.0, 3.0], date_range("2017", periods=4, freq="D")], @@ -325,16 +328,12 @@ def test_arrow_table_roundtrip(breaks): table = pa.table(df) assert isinstance(table.field("a").type, ArrowIntervalType) - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - result = table.to_pandas() + result = table.to_pandas() assert isinstance(result["a"].dtype, pd.IntervalDtype) tm.assert_frame_equal(result, df) table2 = pa.concat_tables([table, table]) - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - result = table2.to_pandas() + result = table2.to_pandas() expected = pd.concat([df, df], ignore_index=True) tm.assert_frame_equal(result, expected) @@ -342,12 +341,13 @@ def test_arrow_table_roundtrip(breaks): table = pa.table( [pa.chunked_array([], type=table.column(0).type)], schema=table.schema ) - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - result = table.to_pandas() + result = table.to_pandas() tm.assert_frame_equal(result, expected[0:0]) +@pytest.mark.filterwarnings( + "ignore:Passing a BlockManager to DataFrame:DeprecationWarning" +) @pytest.mark.parametrize( "breaks", [[0.0, 1.0, 2.0, 3.0], date_range("2017", periods=4, freq="D")], @@ -365,9 +365,7 @@ def test_arrow_table_roundtrip_without_metadata(breaks): table = table.replace_schema_metadata() assert table.schema.metadata is None - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - result = table.to_pandas() + result = table.to_pandas() assert isinstance(result["a"].dtype, pd.IntervalDtype) tm.assert_frame_equal(result, df) diff --git a/pandas/tests/arrays/masked/test_arrow_compat.py b/pandas/tests/arrays/masked/test_arrow_compat.py index 13efc0f60ecef..7a89656bd5aa0 100644 --- a/pandas/tests/arrays/masked/test_arrow_compat.py +++ b/pandas/tests/arrays/masked/test_arrow_compat.py @@ -4,6 +4,10 @@ import pandas as pd import pandas._testing as tm +pytestmark = pytest.mark.filterwarnings( + "ignore:Passing a BlockManager to DataFrame:DeprecationWarning" +) + pa = pytest.importorskip("pyarrow") from pandas.core.arrays.arrow._arrow_utils import pyarrow_array_to_numpy_and_mask @@ -36,9 +40,7 @@ def test_arrow_roundtrip(data): table = pa.table(df) assert table.field("a").type == str(data.dtype.numpy_dtype) - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - result = table.to_pandas() + result = table.to_pandas() assert result["a"].dtype == data.dtype tm.assert_frame_equal(result, df) @@ -56,9 +58,7 @@ def types_mapper(arrow_type): record_batch = pa.RecordBatch.from_arrays( [bools_array, ints_array, small_ints_array], ["bools", "ints", "small_ints"] ) - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - result = record_batch.to_pandas(types_mapper=types_mapper) + result = record_batch.to_pandas(types_mapper=types_mapper) bools = pd.Series([True, None, False], dtype="boolean") ints = pd.Series([1, None, 2], dtype="Int64") small_ints = pd.Series([-1, 0, 7], dtype="Int64") @@ -75,9 +75,7 @@ def test_arrow_load_from_zero_chunks(data): table = pa.table( [pa.chunked_array([], type=table.field("a").type)], schema=table.schema ) - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - result = table.to_pandas() + result = table.to_pandas() assert result["a"].dtype == data.dtype tm.assert_frame_equal(result, df) @@ -98,18 +96,14 @@ def test_arrow_sliced(data): df = pd.DataFrame({"a": data}) table = pa.table(df) - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - result = table.slice(2, None).to_pandas() + result = table.slice(2, None).to_pandas() expected = df.iloc[2:].reset_index(drop=True) tm.assert_frame_equal(result, expected) # no missing values df2 = df.fillna(data[0]) table = pa.table(df2) - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - result = table.slice(2, None).to_pandas() + result = table.slice(2, None).to_pandas() expected = df2.iloc[2:].reset_index(drop=True) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/arrays/period/test_arrow_compat.py b/pandas/tests/arrays/period/test_arrow_compat.py index bb41b564f6db0..6441b188a69c5 100644 --- a/pandas/tests/arrays/period/test_arrow_compat.py +++ b/pandas/tests/arrays/period/test_arrow_compat.py @@ -11,6 +11,11 @@ period_array, ) +pytestmark = pytest.mark.filterwarnings( + "ignore:Passing a BlockManager to DataFrame:DeprecationWarning" +) + + pa = pytest.importorskip("pyarrow") @@ -81,16 +86,12 @@ def test_arrow_table_roundtrip(): table = pa.table(df) assert isinstance(table.field("a").type, ArrowPeriodType) - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - result = table.to_pandas() + result = table.to_pandas() assert isinstance(result["a"].dtype, PeriodDtype) tm.assert_frame_equal(result, df) table2 = pa.concat_tables([table, table]) - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - result = table2.to_pandas() + result = table2.to_pandas() expected = pd.concat([df, df], ignore_index=True) tm.assert_frame_equal(result, expected) @@ -109,9 +110,7 @@ def test_arrow_load_from_zero_chunks(): [pa.chunked_array([], type=table.column(0).type)], schema=table.schema ) - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - result = table.to_pandas() + result = table.to_pandas() assert isinstance(result["a"].dtype, PeriodDtype) tm.assert_frame_equal(result, df) @@ -126,8 +125,6 @@ def test_arrow_table_roundtrip_without_metadata(): table = table.replace_schema_metadata() assert table.schema.metadata is None - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - result = table.to_pandas() + result = table.to_pandas() assert isinstance(result["a"].dtype, PeriodDtype) tm.assert_frame_equal(result, df) diff --git a/pandas/tests/arrays/string_/test_string.py b/pandas/tests/arrays/string_/test_string.py index 052a013eba739..524a6632e5544 100644 --- a/pandas/tests/arrays/string_/test_string.py +++ b/pandas/tests/arrays/string_/test_string.py @@ -488,6 +488,7 @@ def test_arrow_array(dtype): assert arr.equals(expected) +@pytest.mark.filterwarnings("ignore:Passing a BlockManager:DeprecationWarning") def test_arrow_roundtrip(dtype, string_storage2): # roundtrip possible from arrow 1.0.0 pa = pytest.importorskip("pyarrow") @@ -497,9 +498,7 @@ def test_arrow_roundtrip(dtype, string_storage2): table = pa.table(df) assert table.field("a").type == "string" with pd.option_context("string_storage", string_storage2): - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - result = table.to_pandas() + result = table.to_pandas() assert isinstance(result["a"].dtype, pd.StringDtype) expected = df.astype(f"string[{string_storage2}]") tm.assert_frame_equal(result, expected) @@ -507,6 +506,7 @@ def test_arrow_roundtrip(dtype, string_storage2): assert result.loc[2, "a"] is na_val(result["a"].dtype) +@pytest.mark.filterwarnings("ignore:Passing a BlockManager:DeprecationWarning") def test_arrow_load_from_zero_chunks(dtype, string_storage2): # GH-41040 pa = pytest.importorskip("pyarrow") @@ -518,9 +518,7 @@ def test_arrow_load_from_zero_chunks(dtype, string_storage2): # Instantiate the same table with no chunks at all table = pa.table([pa.chunked_array([], type=pa.string())], schema=table.schema) with pd.option_context("string_storage", string_storage2): - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - result = table.to_pandas() + result = table.to_pandas() assert isinstance(result["a"].dtype, pd.StringDtype) expected = df.astype(f"string[{string_storage2}]") tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/copy_view/test_constructors.py b/pandas/tests/copy_view/test_constructors.py index b288d51160534..1f61598c40573 100644 --- a/pandas/tests/copy_view/test_constructors.py +++ b/pandas/tests/copy_view/test_constructors.py @@ -197,7 +197,7 @@ def test_dataframe_constructor_mgr_or_df(using_copy_on_write, columns, use_mgr): data = df warn = None msg = "Passing a BlockManager to DataFrame" - with tm.assert_produces_warning(warn, match=msg): + with tm.assert_produces_warning(warn, match=msg, check_stacklevel=False): new_df = DataFrame(data) assert np.shares_memory(get_array(df, "a"), get_array(new_df, "a")) diff --git a/pandas/tests/frame/test_block_internals.py b/pandas/tests/frame/test_block_internals.py index 295f457bcaeab..8644e11db9b0d 100644 --- a/pandas/tests/frame/test_block_internals.py +++ b/pandas/tests/frame/test_block_internals.py @@ -51,12 +51,16 @@ def test_setitem_invalidates_datetime_index_freq(self): def test_cast_internals(self, float_frame): msg = "Passing a BlockManager to DataFrame" - with tm.assert_produces_warning(DeprecationWarning, match=msg): + with tm.assert_produces_warning( + DeprecationWarning, match=msg, check_stacklevel=False + ): casted = DataFrame(float_frame._mgr, dtype=int) expected = DataFrame(float_frame._series, dtype=int) tm.assert_frame_equal(casted, expected) - with tm.assert_produces_warning(DeprecationWarning, match=msg): + with tm.assert_produces_warning( + DeprecationWarning, match=msg, check_stacklevel=False + ): casted = DataFrame(float_frame._mgr, dtype=np.int32) expected = DataFrame(float_frame._series, dtype=np.int32) tm.assert_frame_equal(casted, expected) diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index ff4fb85fa615a..bf17b61b0e3f3 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -1746,7 +1746,9 @@ def test_constructor_manager_resize(self, float_frame): columns = list(float_frame.columns[:3]) msg = "Passing a BlockManager to DataFrame" - with tm.assert_produces_warning(DeprecationWarning, match=msg): + with tm.assert_produces_warning( + DeprecationWarning, match=msg, check_stacklevel=False + ): result = DataFrame(float_frame._mgr, index=index, columns=columns) tm.assert_index_equal(result.index, Index(index)) tm.assert_index_equal(result.columns, Index(columns)) diff --git a/pandas/tests/io/parser/common/test_common_basic.py b/pandas/tests/io/parser/common/test_common_basic.py index 350bc3f97796a..3abbd14c20e16 100644 --- a/pandas/tests/io/parser/common/test_common_basic.py +++ b/pandas/tests/io/parser/common/test_common_basic.py @@ -88,14 +88,7 @@ def test_read_csv_local(all_parsers, csv1): parser = all_parsers fname = prefix + str(os.path.abspath(csv1)) - - warn = None - if parser.engine == "pyarrow": - warn = DeprecationWarning - msg = "Passing a BlockManager to DataFrame is deprecated" - - with tm.assert_produces_warning(warn, match=msg, check_stacklevel=False): - result = parser.read_csv(fname, index_col=0, parse_dates=True) + result = parser.read_csv(fname, index_col=0, parse_dates=True) # TODO: make unit check more specific if parser.engine == "pyarrow": result.index = result.index.as_unit("ns") diff --git a/pandas/tests/io/parser/conftest.py b/pandas/tests/io/parser/conftest.py index 16ee8ab4106ef..471f525e229e5 100644 --- a/pandas/tests/io/parser/conftest.py +++ b/pandas/tests/io/parser/conftest.py @@ -29,13 +29,20 @@ def read_csv(self, *args, **kwargs): return read_csv(*args, **kwargs) def read_csv_check_warnings( - self, warn_type: type[Warning], warn_msg: str, *args, **kwargs + self, + warn_type: type[Warning], + warn_msg: str, + *args, + raise_on_extra_warnings=True, + **kwargs, ): # We need to check the stacklevel here instead of in the tests # since this is where read_csv is called and where the warning # should point to. kwargs = self.update_kwargs(kwargs) - with tm.assert_produces_warning(warn_type, match=warn_msg): + with tm.assert_produces_warning( + warn_type, match=warn_msg, raise_on_extra_warnings=raise_on_extra_warnings + ): return read_csv(*args, **kwargs) def read_table(self, *args, **kwargs): @@ -43,13 +50,20 @@ def read_table(self, *args, **kwargs): return read_table(*args, **kwargs) def read_table_check_warnings( - self, warn_type: type[Warning], warn_msg: str, *args, **kwargs + self, + warn_type: type[Warning], + warn_msg: str, + *args, + raise_on_extra_warnings=True, + **kwargs, ): # We need to check the stacklevel here instead of in the tests # since this is where read_table is called and where the warning # should point to. kwargs = self.update_kwargs(kwargs) - with tm.assert_produces_warning(warn_type, match=warn_msg): + with tm.assert_produces_warning( + warn_type, match=warn_msg, raise_on_extra_warnings=raise_on_extra_warnings + ): return read_table(*args, **kwargs) diff --git a/pandas/tests/io/parser/test_network.py b/pandas/tests/io/parser/test_network.py index 613284ad096d2..28e5f5ad9bb70 100644 --- a/pandas/tests/io/parser/test_network.py +++ b/pandas/tests/io/parser/test_network.py @@ -20,6 +20,10 @@ from pandas.io.feather_format import read_feather from pandas.io.parsers import read_csv +pytestmark = pytest.mark.filterwarnings( + "ignore:Passing a BlockManager to DataFrame:DeprecationWarning" +) + @pytest.mark.network @pytest.mark.single_cpu diff --git a/pandas/tests/io/parser/test_parse_dates.py b/pandas/tests/io/parser/test_parse_dates.py index 2fd389772ca4f..47e654fc606af 100644 --- a/pandas/tests/io/parser/test_parse_dates.py +++ b/pandas/tests/io/parser/test_parse_dates.py @@ -184,14 +184,12 @@ def date_parser(*date_cols): "keep_date_col": keep_date_col, "names": ["X0", "X1", "X2", "X3", "X4", "X5", "X6", "X7", "X8"], } - warn = FutureWarning - if parser.engine == "pyarrow": - warn = (FutureWarning, DeprecationWarning) result = parser.read_csv_check_warnings( - warn, + FutureWarning, "use 'date_format' instead", StringIO(data), **kwds, + raise_on_extra_warnings=False, ) expected = DataFrame( @@ -506,10 +504,11 @@ def test_multiple_date_cols_int_cast(all_parsers): "date_parser": pd.to_datetime, } result = parser.read_csv_check_warnings( - (FutureWarning, DeprecationWarning), + FutureWarning, "use 'date_format' instead", StringIO(data), **kwds, + raise_on_extra_warnings=False, ) expected = DataFrame( @@ -556,17 +555,14 @@ def test_multiple_date_col_timestamp_parse(all_parsers): data = """05/31/2012,15:30:00.029,1306.25,1,E,0,,1306.25 05/31/2012,15:30:00.029,1306.25,8,E,0,,1306.25""" - warn = FutureWarning - if parser.engine == "pyarrow": - warn = (FutureWarning, DeprecationWarning) - result = parser.read_csv_check_warnings( - warn, + FutureWarning, "use 'date_format' instead", StringIO(data), parse_dates=[[0, 1]], header=None, date_parser=Timestamp, + raise_on_extra_warnings=False, ) expected = DataFrame( [ @@ -722,12 +718,8 @@ def test_date_parser_int_bug(all_parsers): "12345,1,-1,3,invoice_InvoiceResource,search\n" ) - warn = FutureWarning - if parser.engine == "pyarrow": - warn = (FutureWarning, DeprecationWarning) - result = parser.read_csv_check_warnings( - warn, + FutureWarning, "use 'date_format' instead", StringIO(data), index_col=0, @@ -737,6 +729,7 @@ def test_date_parser_int_bug(all_parsers): date_parser=lambda x: datetime.fromtimestamp(int(x), tz=timezone.utc).replace( tzinfo=None ), + raise_on_extra_warnings=False, ) expected = DataFrame( [ @@ -1288,14 +1281,7 @@ def test_bad_date_parse(all_parsers, cache_dates, value): parser = all_parsers s = StringIO((f"{value},\n") * (start_caching_at + 1)) - warn = None - msg = "Passing a BlockManager to DataFrame" - if parser.engine == "pyarrow": - warn = DeprecationWarning - - parser.read_csv_check_warnings( - warn, - msg, + parser.read_csv( s, header=None, names=["foo", "bar"], @@ -1317,24 +1303,22 @@ def test_bad_date_parse_with_warning(all_parsers, cache_dates, value): # pandas doesn't try to guess the datetime format # TODO: parse dates directly in pyarrow, see # https://github.com/pandas-dev/pandas/issues/48017 - warn = DeprecationWarning - msg = "Passing a BlockManager to DataFrame" + warn = None elif cache_dates: # Note: warning is not raised if 'cache_dates', because here there is only a # single unique date and hence no risk of inconsistent parsing. warn = None - msg = None else: warn = UserWarning - msg = "Could not infer format" parser.read_csv_check_warnings( warn, - msg, + "Could not infer format", s, header=None, names=["foo", "bar"], parse_dates=["foo"], cache_dates=cache_dates, + raise_on_extra_warnings=False, ) @@ -1359,17 +1343,14 @@ def test_parse_dates_infer_datetime_format_warning(all_parsers, reader): parser = all_parsers data = "Date,test\n2012-01-01,1\n,2" - warn = FutureWarning - if parser.engine == "pyarrow": - warn = (FutureWarning, DeprecationWarning) - getattr(parser, reader)( - warn, + FutureWarning, "The argument 'infer_datetime_format' is deprecated", StringIO(data), parse_dates=["Date"], infer_datetime_format=True, sep=",", + raise_on_extra_warnings=False, ) @@ -1534,17 +1515,13 @@ def test_parse_date_time_multi_level_column_name(all_parsers): ) def test_parse_date_time(all_parsers, data, kwargs, expected): parser = all_parsers - - warn = FutureWarning - if parser.engine == "pyarrow": - warn = (FutureWarning, DeprecationWarning) - result = parser.read_csv_check_warnings( - warn, + FutureWarning, "use 'date_format' instead", StringIO(data), date_parser=pd.to_datetime, **kwargs, + raise_on_extra_warnings=False, ) # Python can sometimes be flaky about how @@ -1556,19 +1533,15 @@ def test_parse_date_time(all_parsers, data, kwargs, expected): def test_parse_date_fields(all_parsers): parser = all_parsers - - warn = FutureWarning - if parser.engine == "pyarrow": - warn = (FutureWarning, DeprecationWarning) - data = "year,month,day,a\n2001,01,10,10.\n2001,02,1,11." result = parser.read_csv_check_warnings( - warn, + FutureWarning, "use 'date_format' instead", StringIO(data), header=0, parse_dates={"ymd": [0, 1, 2]}, date_parser=lambda x: x, + raise_on_extra_warnings=False, ) expected = DataFrame( @@ -1596,21 +1569,14 @@ def test_parse_date_all_fields(all_parsers, key, value, warn): 2001,01,05,10,00,0,0.0,10. 2001,01,5,10,0,00,1.,11. """ - msg = "use 'date_format' instead" - if parser.engine == "pyarrow": - if warn is None: - msg = "Passing a BlockManager to DataFrame is deprecated" - warn = DeprecationWarning - else: - warn = (warn, DeprecationWarning) - result = parser.read_csv_check_warnings( warn, - msg, + "use 'date_format' instead", StringIO(data), header=0, parse_dates={"ymdHMS": [0, 1, 2, 3, 4, 5]}, **{key: value}, + raise_on_extra_warnings=False, ) expected = DataFrame( [ @@ -1640,21 +1606,14 @@ def test_datetime_fractional_seconds(all_parsers, key, value, warn): 2001,01,05,10,00,0.123456,0.0,10. 2001,01,5,10,0,0.500000,1.,11. """ - msg = "use 'date_format' instead" - if parser.engine == "pyarrow": - if warn is None: - msg = "Passing a BlockManager to DataFrame is deprecated" - warn = DeprecationWarning - else: - warn = (warn, DeprecationWarning) - result = parser.read_csv_check_warnings( warn, - msg, + "use 'date_format' instead", StringIO(data), header=0, parse_dates={"ymdHMS": [0, 1, 2, 3, 4, 5]}, **{key: value}, + raise_on_extra_warnings=False, ) expected = DataFrame( [ @@ -1673,17 +1632,14 @@ def test_generic(all_parsers): def parse_function(yy, mm): return [date(year=int(y), month=int(m), day=1) for y, m in zip(yy, mm)] - warn = FutureWarning - if parser.engine == "pyarrow": - warn = (FutureWarning, DeprecationWarning) - result = parser.read_csv_check_warnings( - warn, + FutureWarning, "use 'date_format' instead", StringIO(data), header=0, parse_dates={"ym": [0, 1]}, date_parser=parse_function, + raise_on_extra_warnings=False, ) expected = DataFrame( [[date(2001, 1, 1), 10, 10.0], [date(2001, 2, 1), 1, 11.0]], @@ -2223,8 +2179,7 @@ def test_parse_dot_separated_dates(all_parsers): dtype="object", name="a", ) - warn = DeprecationWarning - msg = "Passing a BlockManager to DataFrame" + warn = None else: expected_index = DatetimeIndex( ["2003-03-27 14:55:00", "2003-08-03 15:20:00"], @@ -2232,9 +2187,14 @@ def test_parse_dot_separated_dates(all_parsers): name="a", ) warn = UserWarning - msg = r"when dayfirst=False \(the default\) was specified" + msg = r"when dayfirst=False \(the default\) was specified" result = parser.read_csv_check_warnings( - warn, msg, StringIO(data), parse_dates=True, index_col=0 + warn, + msg, + StringIO(data), + parse_dates=True, + index_col=0, + raise_on_extra_warnings=False, ) expected = DataFrame({"b": [1, 2]}, index=expected_index) tm.assert_frame_equal(result, expected) @@ -2271,14 +2231,9 @@ def test_parse_dates_dict_format_two_columns(all_parsers, key, parse_dates): 31-,12-2019 31-,12-2020""" - warn = None - if parser.engine == "pyarrow": - warn = DeprecationWarning - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(warn, match=msg, check_stacklevel=False): - result = parser.read_csv( - StringIO(data), date_format={key: "%d- %m-%Y"}, parse_dates=parse_dates - ) + result = parser.read_csv( + StringIO(data), date_format={key: "%d- %m-%Y"}, parse_dates=parse_dates + ) expected = DataFrame( { key: [Timestamp("2019-12-31"), Timestamp("2020-12-31")], diff --git a/pandas/tests/io/parser/test_unsupported.py b/pandas/tests/io/parser/test_unsupported.py index 468d888590cf8..695dc84db5e25 100644 --- a/pandas/tests/io/parser/test_unsupported.py +++ b/pandas/tests/io/parser/test_unsupported.py @@ -19,6 +19,10 @@ from pandas.io.parsers import read_csv import pandas.io.parsers.readers as parsers +pytestmark = pytest.mark.filterwarnings( + "ignore:Passing a BlockManager to DataFrame:DeprecationWarning" +) + @pytest.fixture(params=["python", "python-fwf"], ids=lambda val: val) def python_engine(request): @@ -157,20 +161,15 @@ def test_on_bad_lines_callable_python_or_pyarrow(self, all_parsers): sio = StringIO("a,b\n1,2") bad_lines_func = lambda x: x parser = all_parsers - warn = None - if parser.engine == "pyarrow": - warn = DeprecationWarning - warn_msg = "Passing a BlockManager" - with tm.assert_produces_warning(warn, match=warn_msg, check_stacklevel=False): - if all_parsers.engine not in ["python", "pyarrow"]: - msg = ( - "on_bad_line can only be a callable " - "function if engine='python' or 'pyarrow'" - ) - with pytest.raises(ValueError, match=msg): - parser.read_csv(sio, on_bad_lines=bad_lines_func) - else: + if all_parsers.engine not in ["python", "pyarrow"]: + msg = ( + "on_bad_line can only be a callable " + "function if engine='python' or 'pyarrow'" + ) + with pytest.raises(ValueError, match=msg): parser.read_csv(sio, on_bad_lines=bad_lines_func) + else: + parser.read_csv(sio, on_bad_lines=bad_lines_func) def test_close_file_handle_on_invalid_usecols(all_parsers): diff --git a/pandas/tests/io/parser/usecols/test_usecols_basic.py b/pandas/tests/io/parser/usecols/test_usecols_basic.py index 2388d9da3f5b5..7a620768040a7 100644 --- a/pandas/tests/io/parser/usecols/test_usecols_basic.py +++ b/pandas/tests/io/parser/usecols/test_usecols_basic.py @@ -16,6 +16,10 @@ ) import pandas._testing as tm +pytestmark = pytest.mark.filterwarnings( + "ignore:Passing a BlockManager to DataFrame:DeprecationWarning" +) + _msg_validate_usecols_arg = ( "'usecols' must either be list-like " "of all strings, all unicode, all " diff --git a/pandas/tests/io/test_orc.py b/pandas/tests/io/test_orc.py index 6b713bfa42b53..a4021311fc963 100644 --- a/pandas/tests/io/test_orc.py +++ b/pandas/tests/io/test_orc.py @@ -70,9 +70,7 @@ def test_orc_reader_empty(dirpath): expected[colname] = pd.Series(dtype=dtype) inputfile = os.path.join(dirpath, "TestOrcFile.emptyFile.orc") - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - got = read_orc(inputfile, columns=columns) + got = read_orc(inputfile, columns=columns) tm.assert_equal(expected, got) @@ -92,9 +90,7 @@ def test_orc_reader_basic(dirpath): expected = pd.DataFrame.from_dict(data) inputfile = os.path.join(dirpath, "TestOrcFile.test1.orc") - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - got = read_orc(inputfile, columns=data.keys()) + got = read_orc(inputfile, columns=data.keys()) tm.assert_equal(expected, got) @@ -121,9 +117,7 @@ def test_orc_reader_decimal(dirpath): expected = pd.DataFrame.from_dict(data) inputfile = os.path.join(dirpath, "TestOrcFile.decimal.orc") - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - got = read_orc(inputfile).iloc[:10] + got = read_orc(inputfile).iloc[:10] tm.assert_equal(expected, got) @@ -164,9 +158,7 @@ def test_orc_reader_date_low(dirpath): expected = pd.DataFrame.from_dict(data) inputfile = os.path.join(dirpath, "TestOrcFile.testDate1900.orc") - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - got = read_orc(inputfile).iloc[:10] + got = read_orc(inputfile).iloc[:10] tm.assert_equal(expected, got) @@ -207,9 +199,7 @@ def test_orc_reader_date_high(dirpath): expected = pd.DataFrame.from_dict(data) inputfile = os.path.join(dirpath, "TestOrcFile.testDate2038.orc") - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - got = read_orc(inputfile).iloc[:10] + got = read_orc(inputfile).iloc[:10] tm.assert_equal(expected, got) @@ -250,9 +240,7 @@ def test_orc_reader_snappy_compressed(dirpath): expected = pd.DataFrame.from_dict(data) inputfile = os.path.join(dirpath, "TestOrcFile.testSnappy.orc") - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - got = read_orc(inputfile).iloc[:10] + got = read_orc(inputfile).iloc[:10] tm.assert_equal(expected, got) @@ -277,9 +265,7 @@ def test_orc_roundtrip_file(dirpath): with tm.ensure_clean() as path: expected.to_orc(path) - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - got = read_orc(path) + got = read_orc(path) tm.assert_equal(expected, got) @@ -303,9 +289,7 @@ def test_orc_roundtrip_bytesio(): expected = pd.DataFrame.from_dict(data) bytes = expected.to_orc() - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - got = read_orc(BytesIO(bytes)) + got = read_orc(BytesIO(bytes)) tm.assert_equal(expected, got) @@ -343,9 +327,7 @@ def test_orc_dtype_backend_pyarrow(): ) bytes_data = df.copy().to_orc() - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - result = read_orc(BytesIO(bytes_data), dtype_backend="pyarrow") + result = read_orc(BytesIO(bytes_data), dtype_backend="pyarrow") expected = pd.DataFrame( { @@ -376,9 +358,7 @@ def test_orc_dtype_backend_numpy_nullable(): ) bytes_data = df.copy().to_orc() - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - result = read_orc(BytesIO(bytes_data), dtype_backend="numpy_nullable") + result = read_orc(BytesIO(bytes_data), dtype_backend="numpy_nullable") expected = pd.DataFrame( { @@ -407,9 +387,7 @@ def test_orc_uri_path(): with tm.ensure_clean("tmp.orc") as path: expected.to_orc(path) uri = pathlib.Path(path).as_uri() - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - result = read_orc(uri) + result = read_orc(uri) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/test_downstream.py b/pandas/tests/test_downstream.py index 5903255118d40..41b4aa97c56f3 100644 --- a/pandas/tests/test_downstream.py +++ b/pandas/tests/test_downstream.py @@ -170,12 +170,11 @@ def test_pandas_datareader(): pytest.importorskip("pandas_datareader") +@pytest.mark.filterwarnings("ignore:Passing a BlockManager:DeprecationWarning") def test_pyarrow(df): pyarrow = pytest.importorskip("pyarrow") table = pyarrow.Table.from_pandas(df) - msg = "Passing a BlockManager to DataFrame is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - result = table.to_pandas() + result = table.to_pandas() tm.assert_frame_equal(result, df)