Skip to content

Commit 55817c7

Browse files
committed
Review (gfyoung)
1 parent 62854f2 commit 55817c7

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

doc/source/whatsnew/v0.25.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ Strings
575575
^^^^^^^
576576

577577
- Bug in the ``__name__`` attribute of several methods of :class:`Series.str`, which were set incorrectly (:issue:`23551`)
578-
- Improved TypeError and shallower stacktrace when passing Series of wrong dtype to :meth:`Series.str.cat` (:issue:`22722`)
578+
- Improved error message when passing ``Series`` of wrong dtype to :meth:`Series.str.cat` (:issue:`22722`)
579579
-
580580

581581

pandas/core/strings.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -2280,13 +2280,16 @@ def cat(self, others=None, sep=None, na_rep=None, join=None):
22802280
'must all be of the same length as the '
22812281
'calling Series/Index.')
22822282

2283+
# data has already been checked by _validate to be of correct dtype,
2284+
# but others could still have Series of dtypes (e.g. integers) which
2285+
# will necessarily fail in concatenation. To avoid deep and confusing
2286+
# traces, we raise here for anything that's not object or all-NA float.
22832287
if any(not (x.dtype == 'O' or (is_categorical_dtype(x)
22842288
and x.cat.categories.dtype == 'O')
22852289
or (x.dtype == 'float' and x.isna().all()))
22862290
for x in others):
2287-
# data has already been checked by str-accessor
22882291
raise TypeError('Can only concatenate list-likes containing only '
2289-
'strings (or missing values)!')
2292+
'strings (or missing values)')
22902293

22912294
if join is None and warn:
22922295
warnings.warn("A future version of pandas will perform index "

pandas/tests/test_strings.py

+1
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ def test_str_cat_categorical(self, box, dtype_caller, dtype_target, sep):
422422

423423
@pytest.mark.parametrize('box', [Series, Index, np.array, list])
424424
def test_str_cat_raise_wrong_dtype(self, box):
425+
# GH 22722
425426
s = Series(['a', 'b', 'c', 'd'])
426427
t = box([1, 2, 3, 4])
427428

0 commit comments

Comments
 (0)