Skip to content

Commit

Permalink
Default behaviour for return_type = None corrected.
Browse files Browse the repository at this point in the history
Added test

bugfix

Final commit
  • Loading branch information
rajat315315 committed Jan 24, 2021
1 parent 9008053 commit f2a89fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def wrap_results_for_axis(
# e.g. test_apply_dict GH#8735
return self.obj._constructor_sliced(results)
elif self.result_type is None and all(
isinstance(x, dict) for x in results.values()
isinstance(x, dict) or isinstance(x, tuple) for x in results.values()
):
# Our operation was a to_dict op e.g.
# test_apply_dict GH#8735, test_apply_reduce_rows_to_dict GH#25196
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/frame/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ def test_apply_empty(self, float_frame):
result = expected.apply(lambda x: x["a"], axis=1)
tm.assert_frame_equal(expected, result)

def test_apply_result_type_None(self):
df = DataFrame([['orig1', 'orig2']])
expected = Series(data=[('new1', 'new2'), ('new1', 'new2')])
result = df.apply(func=lambda col: ('new1', 'new2'))
tm.assert_equal(result, expected)


def test_apply_with_reduce_empty(self):
# reduce with an empty DataFrame
empty_frame = DataFrame()
Expand Down

0 comments on commit f2a89fb

Please sign in to comment.