Skip to content

Commit bdb7386

Browse files
committed
Default behaviour for return_type = None corrected.
Added test bugfix
1 parent c2dfde4 commit bdb7386

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

pandas/core/apply.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,10 @@ def wrap_results_for_axis(
357357
# e.g. test_apply_dict GH#8735
358358
return self.obj._constructor_sliced(results)
359359
elif self.result_type is None and all(
360-
isinstance(x, dict) for x in results.values()
360+
isinstance(x, dict) or isinstance(x, tuple) for x in results.values()
361+
) or (self.axis == 1 and all(
362+
isinstance(x, list) or isinstance(x, tuple) or isinstance(x, dict) for x in results.values()
363+
)
361364
):
362365
# Our operation was a to_dict op e.g.
363366
# test_apply_dict GH#8735, test_apply_reduce_rows_to_dict GH#25196

pandas/tests/frame/test_apply.py

+7
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ def test_apply_empty(self, float_frame):
9797
result = expected.apply(lambda x: x["a"], axis=1)
9898
tm.assert_frame_equal(expected, result)
9999

100+
def test_apply_result_type_None(self):
101+
df = DataFrame([['orig1', 'orig2']])
102+
expected = Series(data=[('new1', 'new2'), ('new1', 'new2')])
103+
result = df.apply(func=lambda col: ('new1', 'new2'))
104+
tm.assert_equal(result, expected)
105+
106+
100107
def test_apply_with_reduce_empty(self):
101108
# reduce with an empty DataFrame
102109
empty_frame = DataFrame()

0 commit comments

Comments
 (0)