From ebdba9ca66d5283e33bf87f952afffc17dc1ab9d Mon Sep 17 00:00:00 2001 From: Abhishek Date: Wed, 20 Nov 2024 13:51:37 +0530 Subject: [PATCH 1/3] added tests for int64 --- pandas/tests/reshape/test_pivot.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index d8a9acdc561fd..de2acf5d3d366 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -2376,17 +2376,20 @@ def test_pivot_table_with_margins_and_numeric_columns(self): tm.assert_frame_equal(result, expected) - def test_pivot_ea_dtype_dropna(self, dropna): + @pytest.mark.parametrize("dtype",['Int64','int64']) + def test_pivot_ea_dtype_dropna(self, dropna,dtype): # GH#47477 - df = DataFrame({"x": "a", "y": "b", "age": Series([20, 40], dtype="Int64")}) + # GH#47971 + df = DataFrame({"x": "a", "y": "b", "age": Series([20, 40], dtype=dtype)}) result = df.pivot_table( index="x", columns="y", values="age", aggfunc="mean", dropna=dropna ) + expected_dtype = "float64" if dtype=="int64" else "Float64" expected = DataFrame( [[30]], index=Index(["a"], name="x"), columns=Index(["b"], name="y"), - dtype="Float64", + dtype=expected_dtype, ) tm.assert_frame_equal(result, expected) From 1f251503055c282058f9c193919e28a37419c99e Mon Sep 17 00:00:00 2001 From: Abhishek Date: Wed, 20 Nov 2024 13:59:45 +0530 Subject: [PATCH 2/3] pre-commit changes --- pandas/tests/reshape/test_pivot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index de2acf5d3d366..b44841ff6be00 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -2376,15 +2376,15 @@ def test_pivot_table_with_margins_and_numeric_columns(self): tm.assert_frame_equal(result, expected) - @pytest.mark.parametrize("dtype",['Int64','int64']) - def test_pivot_ea_dtype_dropna(self, dropna,dtype): + @pytest.mark.parametrize("dtype", ["Int64", "int64"]) + def test_pivot_ea_dtype_dropna(self, dropna, dtype): # GH#47477 # GH#47971 df = DataFrame({"x": "a", "y": "b", "age": Series([20, 40], dtype=dtype)}) result = df.pivot_table( index="x", columns="y", values="age", aggfunc="mean", dropna=dropna ) - expected_dtype = "float64" if dtype=="int64" else "Float64" + expected_dtype = "float64" if dtype == "int64" else "Float64" expected = DataFrame( [[30]], index=Index(["a"], name="x"), From 984b7d6ce71d9dce3622878944b878f8f8ac583b Mon Sep 17 00:00:00 2001 From: Abhishek Date: Thu, 21 Nov 2024 20:01:40 +0530 Subject: [PATCH 3/3] used pytest.mark.parametrize for expected_dtype --- pandas/tests/reshape/test_pivot.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index b44841ff6be00..f42f7f8232229 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -2376,15 +2376,16 @@ def test_pivot_table_with_margins_and_numeric_columns(self): tm.assert_frame_equal(result, expected) - @pytest.mark.parametrize("dtype", ["Int64", "int64"]) - def test_pivot_ea_dtype_dropna(self, dropna, dtype): + @pytest.mark.parametrize( + "dtype,expected_dtype", [("Int64", "Float64"), ("int64", "float64")] + ) + def test_pivot_ea_dtype_dropna(self, dropna, dtype, expected_dtype): # GH#47477 # GH#47971 df = DataFrame({"x": "a", "y": "b", "age": Series([20, 40], dtype=dtype)}) result = df.pivot_table( index="x", columns="y", values="age", aggfunc="mean", dropna=dropna ) - expected_dtype = "float64" if dtype == "int64" else "Float64" expected = DataFrame( [[30]], index=Index(["a"], name="x"),