Better error for str.cat with listlike of wrong dtype. by h-vetinari · Pull Request #26607 · pandas-dev/pandas (original) (raw)
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the try/except + raise into a separate wrapper, as @jreback suggested. This allows to remove the extra check block I had introduced.
However, removing that extra check has the edge case that wrongly dtyped data that is completely misaligned will slip through (i.e. not raise):
>>> s = pd.Series(['a', 'b', 'c'])
>>> t = pd.Series([0, 1, 2], index=[10, 11, 12])
>>> s.str.cat(t, join='left')
0 NaN
1 NaN
2 NaN
dtype: object
It is a downside, but I would be fine with it, not least considering the much less complicated code now.