diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index 3a11e5e4e7226..ad4132d6ca11a 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -477,6 +477,7 @@ Other Deprecations - Deprecated strings ``H``, ``S``, ``U``, and ``N`` denoting units in :func:`to_timedelta` (:issue:`52536`) - Deprecated strings ``H``, ``T``, ``S``, ``L``, ``U``, and ``N`` denoting units in :class:`Timedelta` (:issue:`52536`) - Deprecated strings ``T``, ``S``, ``L``, ``U``, and ``N`` denoting frequencies in :class:`Minute`, :class:`Second`, :class:`Milli`, :class:`Micro`, :class:`Nano` (:issue:`52536`) +- Deprecated the ``verbose`` keyword in :func:`read_csv` and :func:`read_table` (:issue:`55569`) - Deprecated the :attr:`.DataFrameGroupBy.grouper` and :attr:`SeriesGroupBy.grouper`; these attributes will be removed in a future version of pandas (:issue:`56521`) - Deprecated the :class:`.Grouping` attributes ``group_index``, ``result_index``, and ``group_arraylike``; these will be removed in a future version of pandas (:issue:`56148`) - Deprecated the ``errors="ignore"`` option in :func:`to_datetime`, :func:`to_timedelta`, and :func:`to_numeric`; explicitly catch exceptions instead (:issue:`54467`) diff --git a/pandas/io/parsers/readers.py b/pandas/io/parsers/readers.py index 7326ad831ee96..61e8862d85288 100644 --- a/pandas/io/parsers/readers.py +++ b/pandas/io/parsers/readers.py @@ -645,7 +645,7 @@ def read_csv( | Mapping[Hashable, Iterable[Hashable]] | None = ..., na_filter: bool = ..., - verbose: bool = ..., + verbose: bool | lib.NoDefault = ..., skip_blank_lines: bool = ..., parse_dates: bool | Sequence[Hashable] | None = ..., infer_datetime_format: bool | lib.NoDefault = ..., @@ -705,7 +705,7 @@ def read_csv( | None = ..., keep_default_na: bool = ..., na_filter: bool = ..., - verbose: bool = ..., + verbose: bool | lib.NoDefault = ..., skip_blank_lines: bool = ..., parse_dates: bool | Sequence[Hashable] | None = ..., infer_datetime_format: bool | lib.NoDefault = ..., @@ -765,7 +765,7 @@ def read_csv( | None = ..., keep_default_na: bool = ..., na_filter: bool = ..., - verbose: bool = ..., + verbose: bool | lib.NoDefault = ..., skip_blank_lines: bool = ..., parse_dates: bool | Sequence[Hashable] | None = ..., infer_datetime_format: bool | lib.NoDefault = ..., @@ -825,7 +825,7 @@ def read_csv( | None = ..., keep_default_na: bool = ..., na_filter: bool = ..., - verbose: bool = ..., + verbose: bool | lib.NoDefault = ..., skip_blank_lines: bool = ..., parse_dates: bool | Sequence[Hashable] | None = ..., infer_datetime_format: bool | lib.NoDefault = ..., @@ -898,7 +898,7 @@ def read_csv( | None = None, keep_default_na: bool = True, na_filter: bool = True, - verbose: bool = False, + verbose: bool | lib.NoDefault = lib.no_default, skip_blank_lines: bool = True, # Datetime Handling parse_dates: bool | Sequence[Hashable] | None = None, @@ -944,6 +944,18 @@ def read_csv( FutureWarning, stacklevel=find_stack_level(), ) + + if verbose is not lib.no_default: + # GH#55569 + warnings.warn( + "The 'verbose' keyword in pd.read_csv is deprecated and " + "will be removed in a future version.", + FutureWarning, + stacklevel=find_stack_level(), + ) + else: + verbose = False + # locals() should never be modified kwds = locals().copy() del kwds["filepath_or_buffer"] @@ -988,7 +1000,7 @@ def read_table( na_values: Sequence[str] | Mapping[str, Sequence[str]] | None = ..., keep_default_na: bool = ..., na_filter: bool = ..., - verbose: bool = ..., + verbose: bool | lib.NoDefault = ..., skip_blank_lines: bool = ..., parse_dates: bool | Sequence[Hashable] = ..., infer_datetime_format: bool | lib.NoDefault = ..., @@ -1045,7 +1057,7 @@ def read_table( na_values: Sequence[str] | Mapping[str, Sequence[str]] | None = ..., keep_default_na: bool = ..., na_filter: bool = ..., - verbose: bool = ..., + verbose: bool | lib.NoDefault = ..., skip_blank_lines: bool = ..., parse_dates: bool | Sequence[Hashable] = ..., infer_datetime_format: bool | lib.NoDefault = ..., @@ -1102,7 +1114,7 @@ def read_table( na_values: Sequence[str] | Mapping[str, Sequence[str]] | None = ..., keep_default_na: bool = ..., na_filter: bool = ..., - verbose: bool = ..., + verbose: bool | lib.NoDefault = ..., skip_blank_lines: bool = ..., parse_dates: bool | Sequence[Hashable] = ..., infer_datetime_format: bool | lib.NoDefault = ..., @@ -1159,7 +1171,7 @@ def read_table( na_values: Sequence[str] | Mapping[str, Sequence[str]] | None = ..., keep_default_na: bool = ..., na_filter: bool = ..., - verbose: bool = ..., + verbose: bool | lib.NoDefault = ..., skip_blank_lines: bool = ..., parse_dates: bool | Sequence[Hashable] = ..., infer_datetime_format: bool | lib.NoDefault = ..., @@ -1231,7 +1243,7 @@ def read_table( na_values: Sequence[str] | Mapping[str, Sequence[str]] | None = None, keep_default_na: bool = True, na_filter: bool = True, - verbose: bool = False, + verbose: bool | lib.NoDefault = lib.no_default, skip_blank_lines: bool = True, # Datetime Handling parse_dates: bool | Sequence[Hashable] = False, @@ -1278,6 +1290,17 @@ def read_table( stacklevel=find_stack_level(), ) + if verbose is not lib.no_default: + # GH#55569 + warnings.warn( + "The 'verbose' keyword in pd.read_table is deprecated and " + "will be removed in a future version.", + FutureWarning, + stacklevel=find_stack_level(), + ) + else: + verbose = False + # locals() should never be modified kwds = locals().copy() del kwds["filepath_or_buffer"] diff --git a/pandas/tests/io/parser/common/test_verbose.py b/pandas/tests/io/parser/common/test_verbose.py index 14deba8b40b22..fede54643d2dd 100644 --- a/pandas/tests/io/parser/common/test_verbose.py +++ b/pandas/tests/io/parser/common/test_verbose.py @@ -6,6 +6,10 @@ import pytest +import pandas._testing as tm + +depr_msg = "The 'verbose' keyword in pd.read_csv is deprecated" + def test_verbose_read(all_parsers, capsys): parser = all_parsers @@ -22,11 +26,17 @@ def test_verbose_read(all_parsers, capsys): if parser.engine == "pyarrow": msg = "The 'verbose' option is not supported with the 'pyarrow' engine" with pytest.raises(ValueError, match=msg): - parser.read_csv(StringIO(data), verbose=True) + with tm.assert_produces_warning( + FutureWarning, match=depr_msg, check_stacklevel=False + ): + parser.read_csv(StringIO(data), verbose=True) return # Engines are verbose in different ways. - parser.read_csv(StringIO(data), verbose=True) + with tm.assert_produces_warning( + FutureWarning, match=depr_msg, check_stacklevel=False + ): + parser.read_csv(StringIO(data), verbose=True) captured = capsys.readouterr() if parser.engine == "c": @@ -51,10 +61,16 @@ def test_verbose_read2(all_parsers, capsys): if parser.engine == "pyarrow": msg = "The 'verbose' option is not supported with the 'pyarrow' engine" with pytest.raises(ValueError, match=msg): - parser.read_csv(StringIO(data), verbose=True, index_col=0) + with tm.assert_produces_warning( + FutureWarning, match=depr_msg, check_stacklevel=False + ): + parser.read_csv(StringIO(data), verbose=True, index_col=0) return - parser.read_csv(StringIO(data), verbose=True, index_col=0) + with tm.assert_produces_warning( + FutureWarning, match=depr_msg, check_stacklevel=False + ): + parser.read_csv(StringIO(data), verbose=True, index_col=0) captured = capsys.readouterr() # Engines are verbose in different ways. diff --git a/pandas/tests/io/parser/test_unsupported.py b/pandas/tests/io/parser/test_unsupported.py index b099ed53b7a5f..7a9e5b14e5eea 100644 --- a/pandas/tests/io/parser/test_unsupported.py +++ b/pandas/tests/io/parser/test_unsupported.py @@ -152,8 +152,14 @@ def test_pyarrow_engine(self): kwargs[default] = True elif default == "on_bad_lines": kwargs[default] = "warn" + + depr_msg = "The 'verbose' keyword in pd.read_csv is deprecated" + warn = None + if "verbose" in kwargs: + warn = FutureWarning with pytest.raises(ValueError, match=msg): - read_csv(StringIO(data), engine="pyarrow", **kwargs) + with tm.assert_produces_warning(warn, match=depr_msg): + read_csv(StringIO(data), engine="pyarrow", **kwargs) def test_on_bad_lines_callable_python_or_pyarrow(self, all_parsers): # GH 5686