From 2e18f91cd239279c6eb8601bdbcabfdc93f29206 Mon Sep 17 00:00:00 2001 From: tegardp Date: Sat, 29 May 2021 13:35:39 +0700 Subject: [PATCH 1/3] CLN: Deprecate non-keyword arguments in read_table #41485 --- doc/source/whatsnew/v1.3.0.rst | 2 +- pandas/io/parsers/readers.py | 4 +++- pandas/tests/io/parser/common/test_common_basic.py | 11 +++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v1.3.0.rst b/doc/source/whatsnew/v1.3.0.rst index ea9017da8a2f9..38682d188e57a 100644 --- a/doc/source/whatsnew/v1.3.0.rst +++ b/doc/source/whatsnew/v1.3.0.rst @@ -700,7 +700,7 @@ Deprecations - 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`) -- +- Deprecated passing arguments as positional (other than ``filepath_or_buffer``) in :func:`read_table` (:issue:`41485`) .. _whatsnew_130.deprecations.nuisance_columns: diff --git a/pandas/io/parsers/readers.py b/pandas/io/parsers/readers.py index 8bf1ab1260b8e..aa2898f1fb1fb 100644 --- a/pandas/io/parsers/readers.py +++ b/pandas/io/parsers/readers.py @@ -591,7 +591,9 @@ def read_csv( return _read(filepath_or_buffer, kwds) - +@deprecate_nonkeyword_arguments( + version=None, allowed_args=["filepath_or_buffer"], stacklevel=3 +) @Appender( _doc_read_csv_and_table.format( func_name="read_table", diff --git a/pandas/tests/io/parser/common/test_common_basic.py b/pandas/tests/io/parser/common/test_common_basic.py index 97b3be1306cd5..aeec69470dbf9 100644 --- a/pandas/tests/io/parser/common/test_common_basic.py +++ b/pandas/tests/io/parser/common/test_common_basic.py @@ -823,3 +823,14 @@ def test_malformed_second_line(all_parsers): result = parser.read_csv(StringIO(data), skip_blank_lines=False, header=1) expected = DataFrame({"a": ["b"]}) tm.assert_frame_equal(result, expected) + +def test_read_table_posargs_deprecation(all_parsers): + # https://github.com/pandas-dev/pandas/issues/41485 + f = StringIO("a\tb\n1\t2") + parser = all_parsers + msg = ( + "In a future version of pandas all arguments of read_table " + "except for the argument 'filepath_or_buffer' will be keyword-only" + ) + with tm.assert_produces_warning(FutureWarning, match=msg): + parser.read_table(f, " ") From 9a1c6a1f96e6726ddb069598f043c00878fc1098 Mon Sep 17 00:00:00 2001 From: tegardp Date: Sat, 29 May 2021 13:47:01 +0700 Subject: [PATCH 2/3] CLN: Deprecate non-keyword arguments in read_table #41485 --- pandas/io/parsers/readers.py | 1 + pandas/tests/io/parser/common/test_common_basic.py | 1 + 2 files changed, 2 insertions(+) diff --git a/pandas/io/parsers/readers.py b/pandas/io/parsers/readers.py index aa2898f1fb1fb..a384846b7a063 100644 --- a/pandas/io/parsers/readers.py +++ b/pandas/io/parsers/readers.py @@ -591,6 +591,7 @@ def read_csv( return _read(filepath_or_buffer, kwds) + @deprecate_nonkeyword_arguments( version=None, allowed_args=["filepath_or_buffer"], stacklevel=3 ) diff --git a/pandas/tests/io/parser/common/test_common_basic.py b/pandas/tests/io/parser/common/test_common_basic.py index aeec69470dbf9..2be7663a8c1a4 100644 --- a/pandas/tests/io/parser/common/test_common_basic.py +++ b/pandas/tests/io/parser/common/test_common_basic.py @@ -824,6 +824,7 @@ def test_malformed_second_line(all_parsers): expected = DataFrame({"a": ["b"]}) tm.assert_frame_equal(result, expected) + def test_read_table_posargs_deprecation(all_parsers): # https://github.com/pandas-dev/pandas/issues/41485 f = StringIO("a\tb\n1\t2") From 3de379ad51c4c7afa43b1afbe009086d8d40e44e Mon Sep 17 00:00:00 2001 From: tegardp Date: Sun, 30 May 2021 04:40:10 +0700 Subject: [PATCH 3/3] fix single-variable name --- pandas/tests/io/parser/common/test_common_basic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/io/parser/common/test_common_basic.py b/pandas/tests/io/parser/common/test_common_basic.py index 2be7663a8c1a4..8fa2d7f7b8d65 100644 --- a/pandas/tests/io/parser/common/test_common_basic.py +++ b/pandas/tests/io/parser/common/test_common_basic.py @@ -827,11 +827,11 @@ def test_malformed_second_line(all_parsers): def test_read_table_posargs_deprecation(all_parsers): # https://github.com/pandas-dev/pandas/issues/41485 - f = StringIO("a\tb\n1\t2") + data = StringIO("a\tb\n1\t2") parser = all_parsers msg = ( "In a future version of pandas all arguments of read_table " "except for the argument 'filepath_or_buffer' will be keyword-only" ) with tm.assert_produces_warning(FutureWarning, match=msg): - parser.read_table(f, " ") + parser.read_table(data, " ")