Skip to content

Commit

Permalink
deprecate positional args in read_csv (#41657)
Browse files Browse the repository at this point in the history
Co-authored-by: Marco Gorelli <marcogorelli@protonmail.com>
Co-authored-by: Simon Hawkins <simonjayhawkins@gmail.com>
  • Loading branch information
3 people committed May 27, 2021
1 parent 433860b commit 91bd03b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.3.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ Deprecations
- 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`)
- Deprecated passing arguments as positional in :meth:`DataFrame.set_axis` and :meth:`Series.set_axis` (other than ``"labels"``) (:issue:`41485`)
- Deprecated passing arguments as positional in :meth:`DataFrame.where` and :meth:`Series.where` (other than ``"cond"`` and ``"other"``) (:issue:`41485`)
- Deprecated passing arguments as positional (other than ``filepath_or_buffer``) in :func:`read_csv` (:issue:`41485`)
- Deprecated passing arguments as positional in :meth:`DataFrame.drop` (other than ``"labels"``) and :meth:`Series.drop` (:issue:`41485`)
-

Expand Down
8 changes: 7 additions & 1 deletion pandas/io/parsers/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
AbstractMethodError,
ParserWarning,
)
from pandas.util._decorators import Appender
from pandas.util._decorators import (
Appender,
deprecate_nonkeyword_arguments,
)

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


@deprecate_nonkeyword_arguments(
version=None, allowed_args=["filepath_or_buffer"], stacklevel=3
)
@Appender(
_doc_read_csv_and_table.format(
func_name="read_csv",
Expand Down
12 changes: 12 additions & 0 deletions pandas/tests/io/parser/common/test_common_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,18 @@ def test_read_csv_delimiter_and_sep_no_default(all_parsers):
parser.read_csv(f, sep=" ", delimiter=".")


def test_read_csv_posargs_deprecation(all_parsers):
# GH 41485
f = StringIO("a,b\n1,2")
parser = all_parsers
msg = (
"In a future version of pandas all arguments of read_csv "
"except for the argument 'filepath_or_buffer' will be keyword-only"
)
with tm.assert_produces_warning(FutureWarning, match=msg):
parser.read_csv(f, " ")


@pytest.mark.parametrize("delimiter", [",", "\t"])
def test_read_table_delim_whitespace_non_default_sep(all_parsers, delimiter):
# GH: 35958
Expand Down

0 comments on commit 91bd03b

Please sign in to comment.