Skip to content

Commit 6f32d43

Browse files
committed
BUG: sets in str.cat
1 parent 913f71f commit 6f32d43

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

doc/source/whatsnew/v0.24.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ Numeric
875875
Strings
876876
^^^^^^^
877877

878-
-
878+
- Bug in :meth:`Series.str.cat` which falsely did not raise if `others` was a `set` (:issue:`23009`)
879879
-
880880
-
881881

pandas/core/strings.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1996,12 +1996,12 @@ def _get_series_list(self, others, ignore_index=False):
19961996
elif isinstance(others, np.ndarray) and others.ndim == 2:
19971997
others = DataFrame(others, index=idx)
19981998
return ([others[x] for x in others], False)
1999-
elif is_list_like(others):
1999+
elif is_list_like(others) and not isinstance(others, set):
20002000
others = list(others) # ensure iterators do not get read twice etc
20012001

20022002
# in case of list-like `others`, all elements must be
20032003
# either one-dimensional list-likes or scalars
2004-
if all(is_list_like(x) for x in others):
2004+
if all(is_list_like(x) and not isinstance(x, set) for x in others):
20052005
los = []
20062006
join_warn = False
20072007
depr_warn = False

pandas/tests/test_strings.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,15 @@ def test_str_cat_mixed_inputs(self, box):
301301
with tm.assert_raises_regex(TypeError, rgx):
302302
s.str.cat([u, [u, d]])
303303

304-
# forbidden input type, e.g. int
304+
# forbidden input type: set
305+
with tm.assert_raises_regex(TypeError, rgx):
306+
s.str.cat(set(u))
307+
308+
# forbidden input type: set in list
309+
with tm.assert_raises_regex(TypeError, rgx):
310+
s.str.cat([u, set(u)])
311+
312+
# other forbidden input type, e.g. int
305313
with tm.assert_raises_regex(TypeError, rgx):
306314
s.str.cat(1)
307315

0 commit comments

Comments
 (0)