BUG:Pandas 1.0.3 → 1.1.1 behavior change on DataFrame.apply() whith raw option and func returning string · Issue #35940 · pandas-dev/pandas (original) (raw)


df_1 = pd.DataFrame({'A': ["aa","bbb"]}) df_2 = pd.DataFrame({'A': ["bbb","aa"]})

def get_value(array): return array[0]

r_1 = df_1.apply(get_value, axis=1, raw=True) r_2 = df_2.apply(get_value, axis=1, raw=True)

print(r_1) print(r_2)

Output

0 aa
1 bb
dtype: object
0 bbb
1 aa
dtype: object

Problem description

The results are truncated when the smallest strings is first. However, when the result (eg. array[0]) is printed before the return of the func, it's displays the correct value.
(This issue occurred when using apply with the raw option for a function using several columns)

Expected Output

0 aa
1 bbb
dtype: object
0 bbb
1 aa
dtype: object

Output of pd.show_versions()

Pandas 1.1.1
Numpy 1.19.1