From a9a1be1acab438cc5776f4e037b3737a6e57dfac Mon Sep 17 00:00:00 2001 From: Khor Chean Wei Date: Wed, 2 Mar 2022 23:56:14 +0800 Subject: [PATCH 1/5] Update test_frame_apply.py --- pandas/tests/apply/test_frame_apply.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandas/tests/apply/test_frame_apply.py b/pandas/tests/apply/test_frame_apply.py index 98872571ae2bb..59e87d08abc7a 100644 --- a/pandas/tests/apply/test_frame_apply.py +++ b/pandas/tests/apply/test_frame_apply.py @@ -1551,3 +1551,11 @@ def foo(x): df = DataFrame({"a": [1, 2, 3]}) with tm.assert_produces_warning(UserWarning, match="Hello, World!"): df.agg([foo]) + + +def test_apply_return_type(): + # GH 35517 + df = pd.DataFrame([["foo"]]) + result = type(df.apply(lambda col: np.array("bar")).iloc[0]) + expected = np.ndarray + assert result == expected From 16ab035d84dca868cea48135eda8796cd8bd342d Mon Sep 17 00:00:00 2001 From: "chean.wei.khor" Date: Thu, 3 Mar 2022 00:00:16 +0800 Subject: [PATCH 2/5] add --- pandas/tests/apply/test_frame_apply.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandas/tests/apply/test_frame_apply.py b/pandas/tests/apply/test_frame_apply.py index 98872571ae2bb..6be8db6c0136b 100644 --- a/pandas/tests/apply/test_frame_apply.py +++ b/pandas/tests/apply/test_frame_apply.py @@ -1551,3 +1551,11 @@ def foo(x): df = DataFrame({"a": [1, 2, 3]}) with tm.assert_produces_warning(UserWarning, match="Hello, World!"): df.agg([foo]) + + +def test_apply_return_type(): + # GH 35517 + df = DataFrame([["foo"]]) + result = type(df.apply(lambda col: np.array("bar")).iloc[0]) + expected = np.ndarray + assert result == expected From 2c876729023b7988c5feb989de9e859b37413469 Mon Sep 17 00:00:00 2001 From: "chean.wei.khor" Date: Sat, 5 Mar 2022 21:54:03 +0800 Subject: [PATCH 3/5] relocate test case --- pandas/tests/apply/test_frame_apply.py | 8 -------- pandas/tests/frame/methods/test_astype.py | 7 +++++++ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/pandas/tests/apply/test_frame_apply.py b/pandas/tests/apply/test_frame_apply.py index 6be8db6c0136b..98872571ae2bb 100644 --- a/pandas/tests/apply/test_frame_apply.py +++ b/pandas/tests/apply/test_frame_apply.py @@ -1551,11 +1551,3 @@ def foo(x): df = DataFrame({"a": [1, 2, 3]}) with tm.assert_produces_warning(UserWarning, match="Hello, World!"): df.agg([foo]) - - -def test_apply_return_type(): - # GH 35517 - df = DataFrame([["foo"]]) - result = type(df.apply(lambda col: np.array("bar")).iloc[0]) - expected = np.ndarray - assert result == expected diff --git a/pandas/tests/frame/methods/test_astype.py b/pandas/tests/frame/methods/test_astype.py index 6d343de9f5d3a..e685e11e969d5 100644 --- a/pandas/tests/frame/methods/test_astype.py +++ b/pandas/tests/frame/methods/test_astype.py @@ -781,3 +781,10 @@ def test_frame_astype_no_copy(): assert result.a.dtype == pd.Int16Dtype() assert np.shares_memory(df.b.values, result.b.values) + + +def test_frame_apply_np_array_return_type(): + # GH 35517 + df = DataFrame([["foo"]]) + df = df.apply(lambda col: np.array("bar")).iloc[0] + assert isinstance(df, np.ndarray) From 95b3dde8fad25228030d2bff5a82a50132f73b15 Mon Sep 17 00:00:00 2001 From: "chean.wei.khor" Date: Sat, 5 Mar 2022 21:59:12 +0800 Subject: [PATCH 4/5] relocate test case --- pandas/tests/frame/methods/test_astype.py | 7 ------- pandas/tests/frame/methods/test_dtypes.py | 6 ++++++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/pandas/tests/frame/methods/test_astype.py b/pandas/tests/frame/methods/test_astype.py index e685e11e969d5..6d343de9f5d3a 100644 --- a/pandas/tests/frame/methods/test_astype.py +++ b/pandas/tests/frame/methods/test_astype.py @@ -781,10 +781,3 @@ def test_frame_astype_no_copy(): assert result.a.dtype == pd.Int16Dtype() assert np.shares_memory(df.b.values, result.b.values) - - -def test_frame_apply_np_array_return_type(): - # GH 35517 - df = DataFrame([["foo"]]) - df = df.apply(lambda col: np.array("bar")).iloc[0] - assert isinstance(df, np.ndarray) diff --git a/pandas/tests/frame/methods/test_dtypes.py b/pandas/tests/frame/methods/test_dtypes.py index 84841ad7a634e..cf3c0461c4288 100644 --- a/pandas/tests/frame/methods/test_dtypes.py +++ b/pandas/tests/frame/methods/test_dtypes.py @@ -131,3 +131,9 @@ def test_dtypes_timedeltas(self): index=list("ABCD"), ) tm.assert_series_equal(result, expected) + + def test_frame_apply_np_array_return_type(self): + # GH 35517 + df = DataFrame([["foo"]]) + df = df.apply(lambda col: np.array("bar")).iloc[0] + assert isinstance(df, np.ndarray) From 745ae6041a6193977a45bc70c3a7002ae95bfa66 Mon Sep 17 00:00:00 2001 From: "chean.wei.khor" Date: Sun, 6 Mar 2022 12:10:32 +0800 Subject: [PATCH 5/5] remove iloc --- pandas/tests/frame/methods/test_dtypes.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/tests/frame/methods/test_dtypes.py b/pandas/tests/frame/methods/test_dtypes.py index cf3c0461c4288..31592f987f04d 100644 --- a/pandas/tests/frame/methods/test_dtypes.py +++ b/pandas/tests/frame/methods/test_dtypes.py @@ -135,5 +135,6 @@ def test_dtypes_timedeltas(self): def test_frame_apply_np_array_return_type(self): # GH 35517 df = DataFrame([["foo"]]) - df = df.apply(lambda col: np.array("bar")).iloc[0] - assert isinstance(df, np.ndarray) + result = df.apply(lambda col: np.array("bar")) + expected = Series(["bar"]) + tm.assert_series_equal(result, expected)