Skip to content

Commit c6366f5

Browse files
h-vetinarijreback
authored andcommitted
API: change default for sep in str.cat (in docstring) (#23443)
1 parent 11c0d28 commit c6366f5

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

pandas/core/strings.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -2074,9 +2074,10 @@ def cat(self, others=None, sep=None, na_rep=None, join=None):
20742074
20752075
If others is None, the method returns the concatenation of all
20762076
strings in the calling Series/Index.
2077-
sep : string or None, default None
2078-
If None, concatenates without any separator.
2079-
na_rep : string or None, default None
2077+
sep : str, default ''
2078+
The separator between the different elements/columns. By default
2079+
the empty string `''` is used.
2080+
na_rep : str or None, default None
20802081
Representation that is inserted for all missing values:
20812082
20822083
- If `na_rep` is None, and `others` is None, missing values in the

pandas/tests/test_strings.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,11 @@ def test_str_cat_raises_intuitive_error(self, box):
162162
with tm.assert_raises_regex(ValueError, message):
163163
s.str.cat(' ')
164164

165+
@pytest.mark.parametrize('sep', ['', None])
165166
@pytest.mark.parametrize('dtype_target', ['object', 'category'])
166167
@pytest.mark.parametrize('dtype_caller', ['object', 'category'])
167168
@pytest.mark.parametrize('box', [Series, Index])
168-
def test_str_cat_categorical(self, box, dtype_caller, dtype_target):
169+
def test_str_cat_categorical(self, box, dtype_caller, dtype_target, sep):
169170
s = Index(['a', 'a', 'b', 'a'], dtype=dtype_caller)
170171
s = s if box == Index else Series(s, index=s)
171172
t = Index(['b', 'a', 'b', 'c'], dtype=dtype_target)
@@ -176,23 +177,23 @@ def test_str_cat_categorical(self, box, dtype_caller, dtype_target):
176177
# Series/Index with unaligned Index
177178
with tm.assert_produces_warning(expected_warning=FutureWarning):
178179
# FutureWarning to switch to alignment by default
179-
result = s.str.cat(t)
180+
result = s.str.cat(t, sep=sep)
180181
assert_series_or_index_equal(result, expected)
181182

182183
# Series/Index with Series having matching Index
183184
t = Series(t, index=s)
184-
result = s.str.cat(t)
185+
result = s.str.cat(t, sep=sep)
185186
assert_series_or_index_equal(result, expected)
186187

187188
# Series/Index with Series.values
188-
result = s.str.cat(t.values)
189+
result = s.str.cat(t.values, sep=sep)
189190
assert_series_or_index_equal(result, expected)
190191

191192
# Series/Index with Series having different Index
192193
t = Series(t.values, index=t)
193194
with tm.assert_produces_warning(expected_warning=FutureWarning):
194195
# FutureWarning to switch to alignment by default
195-
result = s.str.cat(t)
196+
result = s.str.cat(t, sep=sep)
196197
assert_series_or_index_equal(result, expected)
197198

198199
@pytest.mark.parametrize('box', [Series, Index])

0 commit comments

Comments
 (0)