From 2ad798ec6e9b7c4fc03f89e8b4498eea3a7b3a5c Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sun, 14 Oct 2018 22:40:38 +0100 Subject: [PATCH 1/8] add deprecation warning when delimiter passed --- pandas/io/parsers.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index eeba30ed8a44f..43424bdc8630b 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -635,6 +635,9 @@ def parser_f(filepath_or_buffer, # Alias sep -> delimiter. if delimiter is None: delimiter = sep + else: + warnings.warn("delimiter is deprecated, please use sep instead.", + DeprecationWarning, stacklevel=2) if delim_whitespace and delimiter != default_sep: raise ValueError("Specified a delimiter with both sep and" From 89cf7eac47b75f0f2ea7ea4096bfd8d4b825f816 Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sun, 14 Oct 2018 22:49:58 +0100 Subject: [PATCH 2/8] add deprecated msg in docstring --- pandas/io/parsers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index 43424bdc8630b..67c1a8d34a4ae 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -322,7 +322,10 @@ will also force the use of the Python parsing engine. Note that regex delimiters are prone to ignoring quoted data. Regex example: ``'\r\t'`` delimiter : str, default ``None`` - Alternative argument name for sep.""" + Alternative argument name for sep. + .. deprecated:: 0.23.4 + Use sep argument instead. + """ _read_csv_doc = """ Read CSV (comma-separated) file into DataFrame From 81edb12239f0de5d33002407da417c0d67973b21 Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sun, 14 Oct 2018 22:54:55 +0100 Subject: [PATCH 3/8] update depr version and warning type to future --- pandas/io/parsers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index 67c1a8d34a4ae..9d5246d2a3e04 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -323,7 +323,7 @@ delimiters are prone to ignoring quoted data. Regex example: ``'\r\t'`` delimiter : str, default ``None`` Alternative argument name for sep. - .. deprecated:: 0.23.4 + .. deprecated:: 0.24.0 Use sep argument instead. """ @@ -640,7 +640,7 @@ def parser_f(filepath_or_buffer, delimiter = sep else: warnings.warn("delimiter is deprecated, please use sep instead.", - DeprecationWarning, stacklevel=2) + FutureWarning, stacklevel=2) if delim_whitespace and delimiter != default_sep: raise ValueError("Specified a delimiter with both sep and" From d4b0f7d689512af02227f75de4f59b6bcf6800dc Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sun, 14 Oct 2018 23:30:42 +0100 Subject: [PATCH 4/8] less verbal warning --- pandas/io/parsers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index 9d5246d2a3e04..ac5ba52984cfe 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -639,7 +639,8 @@ def parser_f(filepath_or_buffer, if delimiter is None: delimiter = sep else: - warnings.warn("delimiter is deprecated, please use sep instead.", + # GH 21996 + warnings.warn("delimiter is deprecated, use sep instead.", FutureWarning, stacklevel=2) if delim_whitespace and delimiter != default_sep: From a065d02207b267a42a4a77cfc30f47f3480041db Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sun, 14 Oct 2018 23:31:10 +0100 Subject: [PATCH 5/8] test case for raising warning --- pandas/tests/io/parser/common.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pandas/tests/io/parser/common.py b/pandas/tests/io/parser/common.py index 49e42786d6fb8..de51cf7ca9e4c 100644 --- a/pandas/tests/io/parser/common.py +++ b/pandas/tests/io/parser/common.py @@ -1604,3 +1604,9 @@ def test_buffer_rd_bytes_bad_unicode(self): t = TextIOWrapper(t, encoding='ascii', errors='surrogateescape') with pytest.raises(UnicodeError): pd.read_csv(t, encoding='UTF-8') + + def test_read_csv_depr_delimiter(self): + # GH 21996 + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + self.read_csv(self.csv2, delimiter=',') From d9130f1385e73a8ab5ee7abff73dbe216de8081c Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sun, 14 Oct 2018 23:34:59 +0100 Subject: [PATCH 6/8] fix test and avoid producing unexpected warning --- pandas/tests/io/parser/dialect.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/io/parser/dialect.py b/pandas/tests/io/parser/dialect.py index f756fe71bf684..55b067486dfb7 100644 --- a/pandas/tests/io/parser/dialect.py +++ b/pandas/tests/io/parser/dialect.py @@ -70,9 +70,9 @@ def test_dialect_conflict(self): exp = DataFrame({'a': [1], 'b': [2]}) with tm.assert_produces_warning(None): - df = self.read_csv(StringIO(data), delimiter=',', dialect=dialect) + df = self.read_csv(StringIO(data), sep=',', dialect=dialect) tm.assert_frame_equal(df, exp) with tm.assert_produces_warning(ParserWarning): - df = self.read_csv(StringIO(data), delimiter='.', dialect=dialect) + df = self.read_csv(StringIO(data), sep='.', dialect=dialect) tm.assert_frame_equal(df, exp) From 658e3f8f52b6456493703fa89528db92cf527d8c Mon Sep 17 00:00:00 2001 From: Ming Li Date: Mon, 15 Oct 2018 22:06:36 +0100 Subject: [PATCH 7/8] ignore delimiter warnings where appropriate --- pandas/io/parsers.py | 2 +- pandas/tests/io/parser/c_parser_only.py | 1 + pandas/tests/io/parser/python_parser_only.py | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index ac5ba52984cfe..c3e11faf6e64a 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -641,7 +641,7 @@ def parser_f(filepath_or_buffer, else: # GH 21996 warnings.warn("delimiter is deprecated, use sep instead.", - FutureWarning, stacklevel=2) + FutureWarning, stacklevel=4) if delim_whitespace and delimiter != default_sep: raise ValueError("Specified a delimiter with both sep and" diff --git a/pandas/tests/io/parser/c_parser_only.py b/pandas/tests/io/parser/c_parser_only.py index 9dc7b070f889d..bd3753e7b9f28 100644 --- a/pandas/tests/io/parser/c_parser_only.py +++ b/pandas/tests/io/parser/c_parser_only.py @@ -410,6 +410,7 @@ def test_data_after_quote(self): tm.assert_frame_equal(result, expected) @tm.capture_stderr + @pytest.mark.filterwarnings('ignore::FutureWarning') def test_comment_whitespace_delimited(self): test_input = """\ 1 2 diff --git a/pandas/tests/io/parser/python_parser_only.py b/pandas/tests/io/parser/python_parser_only.py index c0616ebbab4a5..6fba5ef7660a4 100644 --- a/pandas/tests/io/parser/python_parser_only.py +++ b/pandas/tests/io/parser/python_parser_only.py @@ -47,6 +47,7 @@ def test_invalid_skipfooter(self): with tm.assert_raises_regex(ValueError, msg): self.read_csv(StringIO(text), skipfooter=-1) + @pytest.mark.filterwarnings('ignore::FutureWarning') def test_sniff_delimiter(self): text = """index|A|B|C foo|1|2|3 From 2d7b7ab906cebd6ec5b8dad413dac7ef576504bb Mon Sep 17 00:00:00 2001 From: Ming Li Date: Mon, 15 Oct 2018 22:19:33 +0100 Subject: [PATCH 8/8] add whatsnew --- doc/source/whatsnew/v0.24.0.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index 38ef3e3c8daea..2e8a8fd667a96 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -911,6 +911,7 @@ Deprecations - :meth:`FrozenNDArray.searchsorted` has deprecated the ``v`` parameter in favor of ``value`` (:issue:`14645`) - :func:`DatetimeIndex.shift` and :func:`PeriodIndex.shift` now accept ``periods`` argument instead of ``n`` for consistency with :func:`Index.shift` and :func:`Series.shift`. Using ``n`` throws a deprecation warning (:issue:`22458`, :issue:`22912`) - The ``fastpath`` keyword of the different Index constructors is deprecated (:issue:`23110`). +- :meth:`pandas.read_csv` has deprecated the redundant ``delimiter`` argument, please use ``sep`` (:issue:`21996`) .. _whatsnew_0240.prior_deprecations: