From 81b2e47a4f13abda17eff09b30d2c861c341b6b4 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Thu, 19 Oct 2023 09:21:23 +0200 Subject: [PATCH 01/10] DEPR: fix stacklevel for DataFrame(mgr) deprecation --- pandas/core/frame.py | 2 +- pandas/core/series.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 70a5ac69011d1..3894f1f35c9dd 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -696,7 +696,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(): diff --git a/pandas/core/series.py b/pandas/core/series.py index c6e1e460b336a..e5b6927a7814a 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -404,7 +404,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) @@ -443,7 +443,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: @@ -462,7 +462,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)) @@ -536,7 +536,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 From 2ff11b3e527a736960f10b85bbcac1801e54b5b1 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Thu, 19 Oct 2023 09:28:53 +0200 Subject: [PATCH 02/10] revert the added okwarning to user guide --- doc/source/user_guide/10min.rst | 2 -- doc/source/user_guide/io.rst | 11 ----------- doc/source/user_guide/pyarrow.rst | 3 --- doc/source/user_guide/scale.rst | 3 --- doc/source/whatsnew/v2.0.0.rst | 1 - 5 files changed, 20 deletions(-) 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 From 0ab9c6a626f804eec63af9952d7381281c322f53 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Fri, 20 Oct 2023 09:32:12 +0200 Subject: [PATCH 03/10] revert changes to orc tests --- pandas/tests/io/test_orc.py | 44 ++++++++++--------------------------- 1 file changed, 11 insertions(+), 33 deletions(-) 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) From 864115fc230ba9faa1323de3d685211950bd5d35 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Fri, 20 Oct 2023 10:27:00 +0200 Subject: [PATCH 04/10] revert/update some changes in parser tests as well --- .../io/parser/common/test_common_basic.py | 9 +- pandas/tests/io/parser/conftest.py | 22 +++- pandas/tests/io/parser/test_parse_dates.py | 104 ++++++------------ pandas/tests/io/parser/test_unsupported.py | 25 ++--- .../io/parser/usecols/test_usecols_basic.py | 51 +++------ 5 files changed, 78 insertions(+), 133 deletions(-) diff --git a/pandas/tests/io/parser/common/test_common_basic.py b/pandas/tests/io/parser/common/test_common_basic.py index c2f37c75aaab3..86f74059c3484 100644 --- a/pandas/tests/io/parser/common/test_common_basic.py +++ b/pandas/tests/io/parser/common/test_common_basic.py @@ -89,14 +89,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) expected = DataFrame( [ diff --git a/pandas/tests/io/parser/conftest.py b/pandas/tests/io/parser/conftest.py index 591defdde7df9..135e1d7a0502f 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_parse_dates.py b/pandas/tests/io/parser/test_parse_dates.py index c0977be03adef..471b02309cffe 100644 --- a/pandas/tests/io/parser/test_parse_dates.py +++ b/pandas/tests/io/parser/test_parse_dates.py @@ -187,14 +187,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( @@ -509,10 +507,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( @@ -559,17 +558,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( [ @@ -725,12 +721,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, @@ -740,6 +732,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") * 50000) - 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]], @@ -2205,8 +2161,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"], @@ -2214,9 +2169,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) 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 07c94e301b37a..b85e7c3328691 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 " @@ -168,14 +172,9 @@ def test_usecols_index_col_conflict2(all_parsers): expected = DataFrame({"b": ["a", "b"], "c": [1, 2], "d": ("one", "two")}) expected = expected.set_index(["b", "c"]) - msg = "Passing a BlockManager to DataFrame is deprecated" - warn = None - if parser.engine == "pyarrow": - warn = DeprecationWarning - with tm.assert_produces_warning(warn, match=msg, check_stacklevel=False): - result = parser.read_csv( - StringIO(data), usecols=["b", "c", "d"], index_col=["b", "c"] - ) + result = parser.read_csv( + StringIO(data), usecols=["b", "c", "d"], index_col=["b", "c"] + ) tm.assert_frame_equal(result, expected) @@ -196,12 +195,7 @@ def test_usecols_index_col_middle(all_parsers): data = """a,b,c,d 1,2,3,4 """ - msg = "Passing a BlockManager to DataFrame is deprecated" - warn = None - if parser.engine == "pyarrow": - warn = DeprecationWarning - with tm.assert_produces_warning(warn, match=msg, check_stacklevel=False): - result = parser.read_csv(StringIO(data), usecols=["b", "c", "d"], index_col="c") + result = parser.read_csv(StringIO(data), usecols=["b", "c", "d"], index_col="c") expected = DataFrame({"b": [2], "d": [4]}, index=Index([3], name="c")) tm.assert_frame_equal(result, expected) @@ -212,12 +206,7 @@ def test_usecols_index_col_end(all_parsers): data = """a,b,c,d 1,2,3,4 """ - msg = "Passing a BlockManager to DataFrame is deprecated" - warn = None - if parser.engine == "pyarrow": - warn = DeprecationWarning - with tm.assert_produces_warning(warn, match=msg, check_stacklevel=False): - result = parser.read_csv(StringIO(data), usecols=["b", "c", "d"], index_col="d") + result = parser.read_csv(StringIO(data), usecols=["b", "c", "d"], index_col="d") expected = DataFrame({"b": [2], "c": [3]}, index=Index([4], name="d")) tm.assert_frame_equal(result, expected) @@ -283,12 +272,7 @@ def test_np_array_usecols(all_parsers): usecols = np.array(["a", "b"]) expected = DataFrame([[1, 2]], columns=usecols) - msg = "Passing a BlockManager to DataFrame is deprecated" - warn = None - if parser.engine == "pyarrow": - warn = DeprecationWarning - with tm.assert_produces_warning(warn, match=msg, check_stacklevel=False): - result = parser.read_csv(StringIO(data), usecols=usecols) + result = parser.read_csv(StringIO(data), usecols=usecols) tm.assert_frame_equal(result, expected) @@ -480,16 +464,11 @@ def test_usecols_dtype(all_parsers): a,1,x b,2,y """ - msg = "Passing a BlockManager to DataFrame is deprecated" - warn = None - if parser.engine == "pyarrow": - warn = DeprecationWarning - with tm.assert_produces_warning(warn, match=msg, check_stacklevel=False): - result = parser.read_csv( - StringIO(data), - usecols=["col1", "col2"], - dtype={"col1": "string", "col2": "uint8", "col3": "string"}, - ) + result = parser.read_csv( + StringIO(data), + usecols=["col1", "col2"], + dtype={"col1": "string", "col2": "uint8", "col3": "string"}, + ) expected = DataFrame( {"col1": array(["a", "b"]), "col2": np.array([1, 2], dtype="uint8")} ) From 4c15c48aa3b0218c2294343c3535ea383cd91dd1 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Fri, 20 Oct 2023 11:51:56 +0200 Subject: [PATCH 05/10] add back one doc okwarning --- doc/source/user_guide/pyarrow.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/user_guide/pyarrow.rst b/doc/source/user_guide/pyarrow.rst index 61b383afb7c43..e6ee1cc2a14c7 100644 --- a/doc/source/user_guide/pyarrow.rst +++ b/doc/source/user_guide/pyarrow.rst @@ -104,6 +104,7 @@ 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"]) From 20dabc5daf36fbaa9ed84cbd401862a88dedd1aa Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Thu, 26 Oct 2023 14:32:33 +0200 Subject: [PATCH 06/10] use stacklevel of 1 --- pandas/core/frame.py | 2 +- pandas/tests/frame/test_block_internals.py | 8 ++++++-- pandas/tests/frame/test_constructors.py | 4 +++- pandas/tests/io/parser/test_network.py | 4 ++++ 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 8a65fc9266345..4637beb51ae53 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -696,7 +696,7 @@ def __init__( "is deprecated and will raise in a future version. " "Use public APIs instead.", DeprecationWarning, - stacklevel=2, + stacklevel=1, # bump to 2 once pyarrow is released with fix ) if using_copy_on_write(): diff --git a/pandas/tests/frame/test_block_internals.py b/pandas/tests/frame/test_block_internals.py index 8c53ffdd493d6..f4344e97db04d 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 35bc23601eaf4..67c26bb235b01 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -1742,7 +1742,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/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 From ea2bf91f52f63f2d19e06bd29b085b1eaa10212d Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Thu, 26 Oct 2023 14:53:59 +0200 Subject: [PATCH 07/10] Revert "add back one doc okwarning" This reverts commit 4c15c48aa3b0218c2294343c3535ea383cd91dd1. --- doc/source/user_guide/pyarrow.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/user_guide/pyarrow.rst b/doc/source/user_guide/pyarrow.rst index e6ee1cc2a14c7..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"]) From 54a8591fa9772a37aad8297d916f2cdef15f6fb9 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Thu, 26 Oct 2023 16:44:05 +0200 Subject: [PATCH 08/10] fixup more tests --- pandas/tests/arrays/interval/test_interval.py | 22 ++++++++--------- .../tests/arrays/masked/test_arrow_compat.py | 24 +++++++------------ pandas/tests/arrays/string_/test_string.py | 10 ++++---- pandas/tests/copy_view/test_constructors.py | 2 +- pandas/tests/test_downstream.py | 5 ++-- 5 files changed, 26 insertions(+), 37 deletions(-) diff --git a/pandas/tests/arrays/interval/test_interval.py b/pandas/tests/arrays/interval/test_interval.py index 678ff13d99a5f..3637348061bc2 100644 --- a/pandas/tests/arrays/interval/test_interval.py +++ b/pandas/tests/arrays/interval/test_interval.py @@ -321,6 +321,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")], @@ -337,16 +340,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) @@ -354,12 +353,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")], @@ -377,9 +377,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 f11ec5f8a36a0..67c28e637883f 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", minversion="1.0.1") 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/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/test_downstream.py b/pandas/tests/test_downstream.py index 08a1c8e3aebb2..6bc4496af4071 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) From 9042d973762785c114feebae5dda0c5e1aa76d19 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Thu, 26 Oct 2023 17:43:00 +0200 Subject: [PATCH 09/10] fixup more tests --- .../tests/arrays/period/test_arrow_compat.py | 21 ++++++++----------- pandas/tests/io/parser/test_parse_dates.py | 11 +++------- 2 files changed, 12 insertions(+), 20 deletions(-) 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/io/parser/test_parse_dates.py b/pandas/tests/io/parser/test_parse_dates.py index 1e8f4ed3a3b16..565626e35dc60 100644 --- a/pandas/tests/io/parser/test_parse_dates.py +++ b/pandas/tests/io/parser/test_parse_dates.py @@ -2230,14 +2230,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")], From ece6c50a143ae107fcf10fbd71334407b7ff588e Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Wed, 8 Nov 2023 16:48:00 +0100 Subject: [PATCH 10/10] update comment --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index f1115f0d1cb5f..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=1, # bump to 2 once pyarrow is released with fix + stacklevel=1, # bump to 2 once pyarrow 15.0 is released with fix ) if using_copy_on_write():