Skip to content

Commit fd5f878

Browse files
committed
Review (simonjayhawkins)
1 parent 55817c7 commit fd5f878

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

pandas/core/strings.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -2284,10 +2284,13 @@ def cat(self, others=None, sep=None, na_rep=None, join=None):
22842284
# but others could still have Series of dtypes (e.g. integers) which
22852285
# will necessarily fail in concatenation. To avoid deep and confusing
22862286
# traces, we raise here for anything that's not object or all-NA float.
2287-
if any(not (x.dtype == 'O' or (is_categorical_dtype(x)
2288-
and x.cat.categories.dtype == 'O')
2289-
or (x.dtype == 'float' and x.isna().all()))
2290-
for x in others):
2287+
def _legal_dtype(series):
2288+
# unify dtype handling between categorical/non-categorical
2289+
dtype = (series.dtype if not is_categorical_dtype(series)
2290+
else series.cat.categories.dtype)
2291+
legal = dtype == 'O' or (dtype == 'float' and series.isna().all())
2292+
return legal
2293+
if any(not _legal_dtype(x) for x in others):
22912294
raise TypeError('Can only concatenate list-likes containing only '
22922295
'strings (or missing values)')
22932296

pandas/tests/test_strings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ def test_str_cat_categorical(self, box, dtype_caller, dtype_target, sep):
421421
assert_series_or_index_equal(result, expected)
422422

423423
@pytest.mark.parametrize('box', [Series, Index, np.array, list])
424-
def test_str_cat_raise_wrong_dtype(self, box):
424+
def test_str_cat_wrong_dtype_raises(self, box):
425425
# GH 22722
426426
s = Series(['a', 'b', 'c', 'd'])
427427
t = box([1, 2, 3, 4])

0 commit comments

Comments
 (0)