Skip to content

DEPR: verbose kwd in read_csv, read_table #56556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
43 changes: 33 additions & 10 deletions pandas/io/parsers/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ...,
Expand Down Expand Up @@ -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 = ...,
Expand Down Expand Up @@ -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 = ...,
Expand Down Expand Up @@ -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 = ...,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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 = ...,
Expand Down Expand Up @@ -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 = ...,
Expand Down Expand Up @@ -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 = ...,
Expand Down Expand Up @@ -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 = ...,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"]
Expand Down
24 changes: 20 additions & 4 deletions pandas/tests/io/parser/common/test_verbose.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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":
Expand All @@ -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.
Expand Down
8 changes: 7 additions & 1 deletion pandas/tests/io/parser/test_unsupported.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down