Skip to content

Commit 7b2faf0

Browse files
committed
append dtype that's illegal (or has raised) in error message
1 parent 76f1919 commit 7b2faf0

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

pandas/core/strings.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -2291,9 +2291,11 @@ def _legal_dtype(series):
22912291
legal = dtype == 'O' or (dtype == 'float' and series.isna().all())
22922292
return legal
22932293
err_wrong_dtype = ('Can only concatenate list-likes containing only '
2294-
'strings (or missing values)')
2294+
'strings (or missing values).')
22952295
if any(not _legal_dtype(x) for x in others):
2296-
raise TypeError(err_wrong_dtype)
2296+
raise TypeError(err_wrong_dtype + ' Received list-like of dtype: '
2297+
'{}'.format([x.dtype for x in others
2298+
if not _legal_dtype(x)][0]))
22972299

22982300
if join is None and warn:
22992301
warnings.warn("A future version of pandas will perform index "
@@ -2343,9 +2345,12 @@ def _legal_dtype(series):
23432345
# no NaNs - can just concatenate
23442346
result = cat_core(all_cols, sep)
23452347
except TypeError as exc:
2346-
if re.match(r'can only concatenate str \(not \"\w+\"\) to str',
2347-
str(exc)):
2348-
raise TypeError(err_wrong_dtype)
2348+
m = re.match(r'can only concatenate str \(not \"(\w+)\"\) to str',
2349+
str(exc))
2350+
if m:
2351+
raise TypeError(err_wrong_dtype
2352+
+ ' Received list-like containing element of'
2353+
+ ' type: {}'.format(m.group(1)))
23492354
raise exc
23502355

23512356
if isinstance(self._orig, Index):

0 commit comments

Comments
 (0)