Skip to content

Commit 91bd03b

Browse files
Anupam-USPMarcoGorellisimonjayhawkins
authored
deprecate positional args in read_csv (#41657)
Co-authored-by: Marco Gorelli <[email protected]> Co-authored-by: Simon Hawkins <[email protected]>
1 parent 433860b commit 91bd03b

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

doc/source/whatsnew/v1.3.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ Deprecations
697697
- Deprecated construction of :class:`Series` or :class:`DataFrame` with ``DatetimeTZDtype`` data and ``datetime64[ns]`` dtype. Use ``Series(data).dt.tz_localize(None)`` instead (:issue:`41555`,:issue:`33401`)
698698
- Deprecated passing arguments as positional in :meth:`DataFrame.set_axis` and :meth:`Series.set_axis` (other than ``"labels"``) (:issue:`41485`)
699699
- Deprecated passing arguments as positional in :meth:`DataFrame.where` and :meth:`Series.where` (other than ``"cond"`` and ``"other"``) (:issue:`41485`)
700+
- Deprecated passing arguments as positional (other than ``filepath_or_buffer``) in :func:`read_csv` (:issue:`41485`)
700701
- Deprecated passing arguments as positional in :meth:`DataFrame.drop` (other than ``"labels"``) and :meth:`Series.drop` (:issue:`41485`)
701702
-
702703

pandas/io/parsers/readers.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030
AbstractMethodError,
3131
ParserWarning,
3232
)
33-
from pandas.util._decorators import Appender
33+
from pandas.util._decorators import (
34+
Appender,
35+
deprecate_nonkeyword_arguments,
36+
)
3437

3538
from pandas.core.dtypes.common import (
3639
is_file_like,
@@ -472,6 +475,9 @@ def _read(filepath_or_buffer: FilePathOrBuffer, kwds):
472475
return parser.read(nrows)
473476

474477

478+
@deprecate_nonkeyword_arguments(
479+
version=None, allowed_args=["filepath_or_buffer"], stacklevel=3
480+
)
475481
@Appender(
476482
_doc_read_csv_and_table.format(
477483
func_name="read_csv",

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

+12
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,18 @@ def test_read_csv_delimiter_and_sep_no_default(all_parsers):
733733
parser.read_csv(f, sep=" ", delimiter=".")
734734

735735

736+
def test_read_csv_posargs_deprecation(all_parsers):
737+
# GH 41485
738+
f = StringIO("a,b\n1,2")
739+
parser = all_parsers
740+
msg = (
741+
"In a future version of pandas all arguments of read_csv "
742+
"except for the argument 'filepath_or_buffer' will be keyword-only"
743+
)
744+
with tm.assert_produces_warning(FutureWarning, match=msg):
745+
parser.read_csv(f, " ")
746+
747+
736748
@pytest.mark.parametrize("delimiter", [",", "\t"])
737749
def test_read_table_delim_whitespace_non_default_sep(all_parsers, delimiter):
738750
# GH: 35958

0 commit comments

Comments
 (0)