Skip to content

Commit fae8130

Browse files
h-vetinaritm9k1
authored andcommitted
BUG: sets in str.cat (pandas-dev#23187)
1 parent ae91c96 commit fae8130

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

doc/source/whatsnew/v0.24.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ Backwards incompatible API changes
210210
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
211211

212212
- A newly constructed empty :class:`DataFrame` with integer as the ``dtype`` will now only be cast to ``float64`` if ``index`` is specified (:issue:`22858`)
213+
- :meth:`Series.str.cat` will now raise if `others` is a `set` (:issue:`23009`)
213214

214215
.. _whatsnew_0240.api_breaking.deps:
215216

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, allow_sets=False):
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, allow_sets=False) for x in others):
20052005
los = []
20062006
join_warn = False
20072007
depr_warn = False

pandas/tests/test_strings.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,17 @@ 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+
# GH 23009
306+
with tm.assert_raises_regex(TypeError, rgx):
307+
s.str.cat(set(u))
308+
309+
# forbidden input type: set in list
310+
# GH 23009
311+
with tm.assert_raises_regex(TypeError, rgx):
312+
s.str.cat([u, set(u)])
313+
314+
# other forbidden input type, e.g. int
305315
with tm.assert_raises_regex(TypeError, rgx):
306316
s.str.cat(1)
307317

0 commit comments

Comments
 (0)