Skip to content

BUG:Pandas 1.0.3 → 1.1.1 behavior change on DataFrame.apply() whith raw option and func returning string #35940

Closed
@m-hunsicker

Description

@m-hunsicker
  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


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

Metadata

Metadata

Assignees

No one assigned

    Labels

    ApplyApply, Aggregate, Transform, MapBugRegressionFunctionality that used to work in a prior pandas version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions