From 5e2bd40d98e386192c96f7d25e063ce585c9d0f3 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Thu, 1 Nov 2018 09:22:45 +0100 Subject: [PATCH 1/9] API: change default for sep in str.cat --- pandas/core/strings.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index c824ad1712a5a..29d428df6321e 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -2051,7 +2051,7 @@ def _get_series_list(self, others, ignore_index=False): return ([Series(others, index=idx)], False) raise TypeError(err_msg) - def cat(self, others=None, sep=None, na_rep=None, join=None): + def cat(self, others=None, sep='', na_rep=None, join=None): """ Concatenate strings in the Series/Index with given separator. @@ -2074,8 +2074,9 @@ def cat(self, others=None, sep=None, na_rep=None, join=None): If others is None, the method returns the concatenation of all strings in the calling Series/Index. - sep : string or None, default None - If None, concatenates without any separator. + sep : string, default '' + The separator between the different elements/columns. By default + the empty string `''` is used. na_rep : string or None, default None Representation that is inserted for all missing values: @@ -2196,8 +2197,6 @@ def cat(self, others=None, sep=None, na_rep=None, join=None): if isinstance(others, compat.string_types): raise ValueError("Did you mean to supply a `sep` keyword?") - if sep is None: - sep = '' if isinstance(self._orig, Index): data = Series(self._orig, index=self._orig) From d361dceeba1ac28f372bc5157de97718cda69290 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Fri, 2 Nov 2018 16:31:37 +0100 Subject: [PATCH 2/9] Review (jschendel & jreback) --- pandas/core/strings.py | 10 ++++++++-- pandas/tests/test_strings.py | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 29d428df6321e..d57256fbdec85 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -2074,10 +2074,10 @@ def cat(self, others=None, sep='', na_rep=None, join=None): If others is None, the method returns the concatenation of all strings in the calling Series/Index. - sep : string, default '' + sep : str, default '' The separator between the different elements/columns. By default the empty string `''` is used. - na_rep : string or None, default None + na_rep : str or None, default None Representation that is inserted for all missing values: - If `na_rep` is None, and `others` is None, missing values in the @@ -2197,6 +2197,12 @@ def cat(self, others=None, sep='', na_rep=None, join=None): if isinstance(others, compat.string_types): raise ValueError("Did you mean to supply a `sep` keyword?") + if sep is None: + warnings.warn('Passing `sep=None` to .str.cat is deprecated and ' + 'will be removed in a future version. Please use ' + '`sep=''` to pass the default explicitly', + FutureWarning, stacklevel=2) + sep = '' if isinstance(self._orig, Index): data = Series(self._orig, index=self._orig) diff --git a/pandas/tests/test_strings.py b/pandas/tests/test_strings.py index 87bf89229a64e..bb59602764196 100644 --- a/pandas/tests/test_strings.py +++ b/pandas/tests/test_strings.py @@ -162,6 +162,11 @@ def test_str_cat_raises_intuitive_error(self, box): with tm.assert_raises_regex(ValueError, message): s.str.cat(' ') + # GH 23443 + with tm.assert_produces_warning(expected_warning=FutureWarning): + # FutureWarning to switch to default sep='' (instead of None) + s.str.cat(sep=None) + @pytest.mark.parametrize('dtype_target', ['object', 'category']) @pytest.mark.parametrize('dtype_caller', ['object', 'category']) @pytest.mark.parametrize('box', [Series, Index]) From af66b94166c82e7468a51f0e657907c6ed0f6dfb Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Fri, 2 Nov 2018 16:46:27 +0100 Subject: [PATCH 3/9] Retrigger Circle From ae638b99c37c2f038271d182e1b9976157395c78 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Sat, 3 Nov 2018 16:40:27 +0100 Subject: [PATCH 4/9] Review (jreback) --- pandas/core/strings.py | 4 ---- pandas/tests/test_strings.py | 16 ++++++---------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index d57256fbdec85..2740fab6730db 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -2198,10 +2198,6 @@ def cat(self, others=None, sep='', na_rep=None, join=None): if isinstance(others, compat.string_types): raise ValueError("Did you mean to supply a `sep` keyword?") if sep is None: - warnings.warn('Passing `sep=None` to .str.cat is deprecated and ' - 'will be removed in a future version. Please use ' - '`sep=''` to pass the default explicitly', - FutureWarning, stacklevel=2) sep = '' if isinstance(self._orig, Index): diff --git a/pandas/tests/test_strings.py b/pandas/tests/test_strings.py index bb59602764196..f0873eb7683e9 100644 --- a/pandas/tests/test_strings.py +++ b/pandas/tests/test_strings.py @@ -162,15 +162,11 @@ def test_str_cat_raises_intuitive_error(self, box): with tm.assert_raises_regex(ValueError, message): s.str.cat(' ') - # GH 23443 - with tm.assert_produces_warning(expected_warning=FutureWarning): - # FutureWarning to switch to default sep='' (instead of None) - s.str.cat(sep=None) - + @pytest.mark.parametrize('sep', ['', None]) @pytest.mark.parametrize('dtype_target', ['object', 'category']) @pytest.mark.parametrize('dtype_caller', ['object', 'category']) @pytest.mark.parametrize('box', [Series, Index]) - def test_str_cat_categorical(self, box, dtype_caller, dtype_target): + def test_str_cat_categorical(self, box, dtype_caller, dtype_target, sep): s = Index(['a', 'a', 'b', 'a'], dtype=dtype_caller) s = s if box == Index else Series(s, index=s) t = Index(['b', 'a', 'b', 'c'], dtype=dtype_target) @@ -181,23 +177,23 @@ def test_str_cat_categorical(self, box, dtype_caller, dtype_target): # Series/Index with unaligned Index with tm.assert_produces_warning(expected_warning=FutureWarning): # FutureWarning to switch to alignment by default - result = s.str.cat(t) + result = s.str.cat(t, sep=sep) assert_series_or_index_equal(result, expected) # Series/Index with Series having matching Index t = Series(t, index=s) - result = s.str.cat(t) + result = s.str.cat(t, sep=sep) assert_series_or_index_equal(result, expected) # Series/Index with Series.values - result = s.str.cat(t.values) + result = s.str.cat(t.values, sep=sep) assert_series_or_index_equal(result, expected) # Series/Index with Series having different Index t = Series(t.values, index=t) with tm.assert_produces_warning(expected_warning=FutureWarning): # FutureWarning to switch to alignment by default - result = s.str.cat(t) + result = s.str.cat(t, sep=sep) assert_series_or_index_equal(result, expected) @pytest.mark.parametrize('box', [Series, Index]) From 712642b53ba8d6dee2a29f556ba993485927385b Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Sat, 3 Nov 2018 16:58:37 +0100 Subject: [PATCH 5/9] Retrigger CircleCI From 29be9751321d6255036dc5a0484c4d824aeb179e Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Sat, 3 Nov 2018 17:01:23 +0100 Subject: [PATCH 6/9] Retrigger CircleCI From 0f3251082e13439b0e52b629932641c6a80263af Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Mon, 5 Nov 2018 01:16:12 +0100 Subject: [PATCH 7/9] Review (jreback) --- pandas/core/strings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 2740fab6730db..18a83269a2f0f 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -2051,7 +2051,7 @@ def _get_series_list(self, others, ignore_index=False): return ([Series(others, index=idx)], False) raise TypeError(err_msg) - def cat(self, others=None, sep='', na_rep=None, join=None): + def cat(self, others=None, sep=None, na_rep=None, join=None): """ Concatenate strings in the Series/Index with given separator. From 608f2d2df47941fd7454d5a35f43941a4a037b93 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Mon, 5 Nov 2018 01:17:04 +0100 Subject: [PATCH 8/9] Retrigger CircleCI From 2d1bf05cf3c50f40890a9bc035e506521ae404a0 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Mon, 5 Nov 2018 19:15:52 +0100 Subject: [PATCH 9/9] Retrigger Circle