Skip to content

BUG: sets in str.cat #23187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ Backwards incompatible API changes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

.. _whatsnew_0240.api_breaking.deps:

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1996,12 +1996,12 @@ def _get_series_list(self, others, ignore_index=False):
elif isinstance(others, np.ndarray) and others.ndim == 2:
others = DataFrame(others, index=idx)
return ([others[x] for x in others], False)
elif is_list_like(others):
elif is_list_like(others, allow_sets=False):
others = list(others) # ensure iterators do not get read twice etc

# in case of list-like `others`, all elements must be
# either one-dimensional list-likes or scalars
if all(is_list_like(x) for x in others):
if all(is_list_like(x, allow_sets=False) for x in others):
los = []
join_warn = False
depr_warn = False
Expand Down
12 changes: 11 additions & 1 deletion pandas/tests/test_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,17 @@ def test_str_cat_mixed_inputs(self, box):
with tm.assert_raises_regex(TypeError, rgx):
s.str.cat([u, [u, d]])

# forbidden input type, e.g. int
# forbidden input type: set
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add the issue number here

# GH 23009
with tm.assert_raises_regex(TypeError, rgx):
s.str.cat(set(u))

# forbidden input type: set in list
# GH 23009
with tm.assert_raises_regex(TypeError, rgx):
s.str.cat([u, set(u)])

# other forbidden input type, e.g. int
with tm.assert_raises_regex(TypeError, rgx):
s.str.cat(1)

Expand Down