Skip to content
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

FIX: add additional condition to check invalid type(#28277) #28319

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 3 additions & 1 deletion pandas/core/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2107,7 +2107,9 @@ def _get_series_list(self, others):
elif isinstance(others, np.ndarray) and others.ndim == 2:
others = DataFrame(others, index=idx)
return [others[x] for x in others]
elif is_list_like(others, allow_sets=False):
elif is_list_like(others, allow_sets=False) and not isinstance(
Copy link
Member

Choose a reason for hiding this comment

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

Not sure about this. I think the real issue is that is_list_like returns True for s.str when it shouldn't, though I do see that is also technically Iterable so maybe this should be allowed and just fixed

others, type(self)
):
others = list(others) # ensure iterators do not get read twice etc

# in case of list-like `others`, all elements must be
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/test_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@ def test_str_cat_raises_intuitive_error(self, box):
with pytest.raises(ValueError, match=message):
s.str.cat(" ")

# test whether error is raise when others is StringMethod
message = "others must be Series, Index, DataFrame,.*"
with pytest.raises(TypeError, match=message):
s.str.cat(others=s.str)

@pytest.mark.parametrize("sep", ["", None])
@pytest.mark.parametrize("dtype_target", ["object", "category"])
@pytest.mark.parametrize("dtype_caller", ["object", "category"])
Expand Down