Skip to content

Commit 87a9c55

Browse files
DEPR: verbose kwd in read_csv, read_table (#56556)
* DEPR: verbose kwd in read_csv, read_table * Update doc/source/whatsnew/v2.2.0.rst Co-authored-by: Matthew Roeschke <[email protected]> --------- Co-authored-by: Matthew Roeschke <[email protected]>
1 parent 99e6897 commit 87a9c55

File tree

4 files changed

+61
-15
lines changed

4 files changed

+61
-15
lines changed

doc/source/whatsnew/v2.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ Other Deprecations
480480
- Deprecated strings ``H``, ``S``, ``U``, and ``N`` denoting units in :func:`to_timedelta` (:issue:`52536`)
481481
- Deprecated strings ``H``, ``T``, ``S``, ``L``, ``U``, and ``N`` denoting units in :class:`Timedelta` (:issue:`52536`)
482482
- Deprecated strings ``T``, ``S``, ``L``, ``U``, and ``N`` denoting frequencies in :class:`Minute`, :class:`Second`, :class:`Milli`, :class:`Micro`, :class:`Nano` (:issue:`52536`)
483+
- Deprecated the ``verbose`` keyword in :func:`read_csv` and :func:`read_table` (:issue:`55569`)
483484
- Deprecated the :attr:`.DataFrameGroupBy.grouper` and :attr:`SeriesGroupBy.grouper`; these attributes will be removed in a future version of pandas (:issue:`56521`)
484485
- Deprecated the :class:`.Grouping` attributes ``group_index``, ``result_index``, and ``group_arraylike``; these will be removed in a future version of pandas (:issue:`56148`)
485486
- Deprecated the ``errors="ignore"`` option in :func:`to_datetime`, :func:`to_timedelta`, and :func:`to_numeric`; explicitly catch exceptions instead (:issue:`54467`)

pandas/io/parsers/readers.py

+33-10
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ def read_csv(
645645
| Mapping[Hashable, Iterable[Hashable]]
646646
| None = ...,
647647
na_filter: bool = ...,
648-
verbose: bool = ...,
648+
verbose: bool | lib.NoDefault = ...,
649649
skip_blank_lines: bool = ...,
650650
parse_dates: bool | Sequence[Hashable] | None = ...,
651651
infer_datetime_format: bool | lib.NoDefault = ...,
@@ -705,7 +705,7 @@ def read_csv(
705705
| None = ...,
706706
keep_default_na: bool = ...,
707707
na_filter: bool = ...,
708-
verbose: bool = ...,
708+
verbose: bool | lib.NoDefault = ...,
709709
skip_blank_lines: bool = ...,
710710
parse_dates: bool | Sequence[Hashable] | None = ...,
711711
infer_datetime_format: bool | lib.NoDefault = ...,
@@ -765,7 +765,7 @@ def read_csv(
765765
| None = ...,
766766
keep_default_na: bool = ...,
767767
na_filter: bool = ...,
768-
verbose: bool = ...,
768+
verbose: bool | lib.NoDefault = ...,
769769
skip_blank_lines: bool = ...,
770770
parse_dates: bool | Sequence[Hashable] | None = ...,
771771
infer_datetime_format: bool | lib.NoDefault = ...,
@@ -825,7 +825,7 @@ def read_csv(
825825
| None = ...,
826826
keep_default_na: bool = ...,
827827
na_filter: bool = ...,
828-
verbose: bool = ...,
828+
verbose: bool | lib.NoDefault = ...,
829829
skip_blank_lines: bool = ...,
830830
parse_dates: bool | Sequence[Hashable] | None = ...,
831831
infer_datetime_format: bool | lib.NoDefault = ...,
@@ -898,7 +898,7 @@ def read_csv(
898898
| None = None,
899899
keep_default_na: bool = True,
900900
na_filter: bool = True,
901-
verbose: bool = False,
901+
verbose: bool | lib.NoDefault = lib.no_default,
902902
skip_blank_lines: bool = True,
903903
# Datetime Handling
904904
parse_dates: bool | Sequence[Hashable] | None = None,
@@ -944,6 +944,18 @@ def read_csv(
944944
FutureWarning,
945945
stacklevel=find_stack_level(),
946946
)
947+
948+
if verbose is not lib.no_default:
949+
# GH#55569
950+
warnings.warn(
951+
"The 'verbose' keyword in pd.read_csv is deprecated and "
952+
"will be removed in a future version.",
953+
FutureWarning,
954+
stacklevel=find_stack_level(),
955+
)
956+
else:
957+
verbose = False
958+
947959
# locals() should never be modified
948960
kwds = locals().copy()
949961
del kwds["filepath_or_buffer"]
@@ -988,7 +1000,7 @@ def read_table(
9881000
na_values: Sequence[str] | Mapping[str, Sequence[str]] | None = ...,
9891001
keep_default_na: bool = ...,
9901002
na_filter: bool = ...,
991-
verbose: bool = ...,
1003+
verbose: bool | lib.NoDefault = ...,
9921004
skip_blank_lines: bool = ...,
9931005
parse_dates: bool | Sequence[Hashable] = ...,
9941006
infer_datetime_format: bool | lib.NoDefault = ...,
@@ -1045,7 +1057,7 @@ def read_table(
10451057
na_values: Sequence[str] | Mapping[str, Sequence[str]] | None = ...,
10461058
keep_default_na: bool = ...,
10471059
na_filter: bool = ...,
1048-
verbose: bool = ...,
1060+
verbose: bool | lib.NoDefault = ...,
10491061
skip_blank_lines: bool = ...,
10501062
parse_dates: bool | Sequence[Hashable] = ...,
10511063
infer_datetime_format: bool | lib.NoDefault = ...,
@@ -1102,7 +1114,7 @@ def read_table(
11021114
na_values: Sequence[str] | Mapping[str, Sequence[str]] | None = ...,
11031115
keep_default_na: bool = ...,
11041116
na_filter: bool = ...,
1105-
verbose: bool = ...,
1117+
verbose: bool | lib.NoDefault = ...,
11061118
skip_blank_lines: bool = ...,
11071119
parse_dates: bool | Sequence[Hashable] = ...,
11081120
infer_datetime_format: bool | lib.NoDefault = ...,
@@ -1159,7 +1171,7 @@ def read_table(
11591171
na_values: Sequence[str] | Mapping[str, Sequence[str]] | None = ...,
11601172
keep_default_na: bool = ...,
11611173
na_filter: bool = ...,
1162-
verbose: bool = ...,
1174+
verbose: bool | lib.NoDefault = ...,
11631175
skip_blank_lines: bool = ...,
11641176
parse_dates: bool | Sequence[Hashable] = ...,
11651177
infer_datetime_format: bool | lib.NoDefault = ...,
@@ -1231,7 +1243,7 @@ def read_table(
12311243
na_values: Sequence[str] | Mapping[str, Sequence[str]] | None = None,
12321244
keep_default_na: bool = True,
12331245
na_filter: bool = True,
1234-
verbose: bool = False,
1246+
verbose: bool | lib.NoDefault = lib.no_default,
12351247
skip_blank_lines: bool = True,
12361248
# Datetime Handling
12371249
parse_dates: bool | Sequence[Hashable] = False,
@@ -1278,6 +1290,17 @@ def read_table(
12781290
stacklevel=find_stack_level(),
12791291
)
12801292

1293+
if verbose is not lib.no_default:
1294+
# GH#55569
1295+
warnings.warn(
1296+
"The 'verbose' keyword in pd.read_table is deprecated and "
1297+
"will be removed in a future version.",
1298+
FutureWarning,
1299+
stacklevel=find_stack_level(),
1300+
)
1301+
else:
1302+
verbose = False
1303+
12811304
# locals() should never be modified
12821305
kwds = locals().copy()
12831306
del kwds["filepath_or_buffer"]

pandas/tests/io/parser/common/test_verbose.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
import pytest
88

9+
import pandas._testing as tm
10+
11+
depr_msg = "The 'verbose' keyword in pd.read_csv is deprecated"
12+
913

1014
def test_verbose_read(all_parsers, capsys):
1115
parser = all_parsers
@@ -22,11 +26,17 @@ def test_verbose_read(all_parsers, capsys):
2226
if parser.engine == "pyarrow":
2327
msg = "The 'verbose' option is not supported with the 'pyarrow' engine"
2428
with pytest.raises(ValueError, match=msg):
25-
parser.read_csv(StringIO(data), verbose=True)
29+
with tm.assert_produces_warning(
30+
FutureWarning, match=depr_msg, check_stacklevel=False
31+
):
32+
parser.read_csv(StringIO(data), verbose=True)
2633
return
2734

2835
# Engines are verbose in different ways.
29-
parser.read_csv(StringIO(data), verbose=True)
36+
with tm.assert_produces_warning(
37+
FutureWarning, match=depr_msg, check_stacklevel=False
38+
):
39+
parser.read_csv(StringIO(data), verbose=True)
3040
captured = capsys.readouterr()
3141

3242
if parser.engine == "c":
@@ -51,10 +61,16 @@ def test_verbose_read2(all_parsers, capsys):
5161
if parser.engine == "pyarrow":
5262
msg = "The 'verbose' option is not supported with the 'pyarrow' engine"
5363
with pytest.raises(ValueError, match=msg):
54-
parser.read_csv(StringIO(data), verbose=True, index_col=0)
64+
with tm.assert_produces_warning(
65+
FutureWarning, match=depr_msg, check_stacklevel=False
66+
):
67+
parser.read_csv(StringIO(data), verbose=True, index_col=0)
5568
return
5669

57-
parser.read_csv(StringIO(data), verbose=True, index_col=0)
70+
with tm.assert_produces_warning(
71+
FutureWarning, match=depr_msg, check_stacklevel=False
72+
):
73+
parser.read_csv(StringIO(data), verbose=True, index_col=0)
5874
captured = capsys.readouterr()
5975

6076
# Engines are verbose in different ways.

pandas/tests/io/parser/test_unsupported.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,14 @@ def test_pyarrow_engine(self):
152152
kwargs[default] = True
153153
elif default == "on_bad_lines":
154154
kwargs[default] = "warn"
155+
156+
depr_msg = "The 'verbose' keyword in pd.read_csv is deprecated"
157+
warn = None
158+
if "verbose" in kwargs:
159+
warn = FutureWarning
155160
with pytest.raises(ValueError, match=msg):
156-
read_csv(StringIO(data), engine="pyarrow", **kwargs)
161+
with tm.assert_produces_warning(warn, match=depr_msg):
162+
read_csv(StringIO(data), engine="pyarrow", **kwargs)
157163

158164
def test_on_bad_lines_callable_python_or_pyarrow(self, all_parsers):
159165
# GH 5686

0 commit comments

Comments
 (0)