str.cat not working with binary data on Python3 · Issue #22721 · pandas-dev/pandas (original) (raw)

In Python 2, the following works:

s = pd.Series(np.array(list('abc'), 'S1').astype(object))
t = pd.Series(np.array(list('def'), 'S1').astype(object))
s.str.cat(t)
# 0    b'ad'
# 1    b'be'
# 2    b'cf'
# dtype: object

whereas in Python 3, s.str.cat(t) yields:

TypeError: sequence item 0: expected str instance, bytes found

Clearly, Python 3 fundamentally changed the separation between bytes and strings, but in principle, there is no reason (other than implementation) why this should not have the same result in Python 3 as in Python 2.