diff --git a/pandas/core/strings.py b/pandas/core/strings.py index c824ad1712a5a..18a83269a2f0f 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -2074,9 +2074,10 @@ 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. - na_rep : string or None, default None + sep : str, default '' + The separator between the different elements/columns. By default + the empty string `''` is used. + 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 diff --git a/pandas/tests/test_strings.py b/pandas/tests/test_strings.py index 87bf89229a64e..f0873eb7683e9 100644 --- a/pandas/tests/test_strings.py +++ b/pandas/tests/test_strings.py @@ -162,10 +162,11 @@ def test_str_cat_raises_intuitive_error(self, box): with tm.assert_raises_regex(ValueError, message): s.str.cat(' ') + @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) @@ -176,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])