diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 25350119f9df5..c388db8219a1d 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -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( + others, type(self) + ): others = list(others) # ensure iterators do not get read twice etc # in case of list-like `others`, all elements must be diff --git a/pandas/tests/test_strings.py b/pandas/tests/test_strings.py index bc8dc7272a83a..e7725476407ee 100644 --- a/pandas/tests/test_strings.py +++ b/pandas/tests/test_strings.py @@ -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"])