From 0b801a91f0dc58f94323836ef7bf057799da2e4d Mon Sep 17 00:00:00 2001 From: boomsquared Date: Fri, 6 Sep 2019 22:59:06 +0700 Subject: [PATCH 1/3] FIX: add additional condition to check invalid type(#28277) --- pandas/core/strings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 25350119f9df5..e391e810b3cca 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -2107,7 +2107,7 @@ 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 From fb6c825dd71b3131136ab7ad8ecce66dd7821deb Mon Sep 17 00:00:00 2001 From: boomsquared Date: Fri, 6 Sep 2019 23:13:33 +0700 Subject: [PATCH 2/3] CLN: fix pep8 E231 and E501 --- pandas/core/strings.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index e391e810b3cca..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) and not isinstance(others,type(self)): + 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 From d8e28b59039e914d0f66278ef288c57d47bdaba9 Mon Sep 17 00:00:00 2001 From: boomsquared Date: Sat, 7 Sep 2019 02:31:02 +0700 Subject: [PATCH 3/3] TST: add testcase in test_str_cat_raises_intuitive_error(#28277) --- pandas/tests/test_strings.py | 5 +++++ 1 file changed, 5 insertions(+) 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"])