Skip to content

Commit d8d8b01

Browse files
committed
Review (gfyoung)
1 parent 81451bd commit d8d8b01

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

doc/source/whatsnew/v0.25.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ Strings
574574
^^^^^^^
575575

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

580580

pandas/core/strings.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -2280,11 +2280,14 @@ 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 '
22892292
'strings (or missing values)!')
22902293

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)