From 2eec4f7cfa1c45671b9875062343521a53ae8b28 Mon Sep 17 00:00:00 2001 From: Rajat Jain Date: Sun, 24 Jan 2021 19:01:56 +0530 Subject: [PATCH] Fixed code breakage for tuples for axis = 0 PEP error fixed Modified previous commit --- pandas/core/apply.py | 2 +- pandas/tests/apply/test_frame_apply.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pandas/core/apply.py b/pandas/core/apply.py index 3374e07c53cad..7e384fb3855f6 100644 --- a/pandas/core/apply.py +++ b/pandas/core/apply.py @@ -482,7 +482,7 @@ def wrap_results_for_axis( return res elif self.result_type is None and all( - isinstance(x, dict) for x in results.values() + isinstance(x, (dict, tuple)) for x in results.values() ): # Our operation was a to_dict op e.g. # test_apply_dict GH#8735, test_apply_reduce_to_dict GH#25196 #37544 diff --git a/pandas/tests/apply/test_frame_apply.py b/pandas/tests/apply/test_frame_apply.py index dd8904674428f..df01a1982605d 100644 --- a/pandas/tests/apply/test_frame_apply.py +++ b/pandas/tests/apply/test_frame_apply.py @@ -131,6 +131,14 @@ def test_apply_funcs_over_empty(self, func): expected = getattr(df, func)() tm.assert_series_equal(result, expected) + def test_apply_return_type_none(self): + # GH 35518 + df = DataFrame([["orig1", "orig2"], ["orig3", "orig4"]]) + result = df.apply(func=lambda col: ("new1", "new2")) + + expected = Series(data=[("new1", "new2"), ("new1", "new2")]) + tm.assert_series_equal(result, expected) + def test_nunique_empty(self): # GH 28213 df = DataFrame(columns=["a", "b", "c"])