From 4c66d90be4330f8b27111a47dc6a36942c9f9236 Mon Sep 17 00:00:00 2001 From: lvs1 Date: Thu, 10 Dec 2020 08:41:38 -0800 Subject: [PATCH 1/5] TST: Add test to ensure Dataframe describe does not throw an error (#32409) --- pandas/tests/frame/methods/test_describe.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pandas/tests/frame/methods/test_describe.py b/pandas/tests/frame/methods/test_describe.py index 1de270fc72fb2..7a37e35df740a 100644 --- a/pandas/tests/frame/methods/test_describe.py +++ b/pandas/tests/frame/methods/test_describe.py @@ -376,3 +376,14 @@ def test_describe_when_include_all_exclude_not_allowed(self, exclude): msg = "exclude must be None when include is 'all'" with pytest.raises(ValueError, match=msg): df.describe(include="all", exclude=exclude) + + def test_describe_does_not_raise_error(self): + # GH#32409 + df = DataFrame([{"test": {"a": "1"}}, {"test": {"a": "2"}}]) + expected = DataFrame( + {"test": [2, 2, {"a": "1"}, 1]}, index=["count", "unique", "top", "freq"] + ) + result = df.describe() + tm.assert_frame_equal(result, expected) + exp_repr = " test\n" "count 2\n" "unique 2\n" "top {'a': '1'}\n" "freq 1" + assert repr(result) == exp_repr From a22423d51b1e2683276873c0fd9fe6745290ac55 Mon Sep 17 00:00:00 2001 From: lvs1 Date: Thu, 10 Dec 2020 09:12:44 -0800 Subject: [PATCH 2/5] TST: Update linting from Black to CI required for spacing (#32409) --- pandas/tests/frame/methods/test_describe.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pandas/tests/frame/methods/test_describe.py b/pandas/tests/frame/methods/test_describe.py index 7a37e35df740a..8d6e0c773ae98 100644 --- a/pandas/tests/frame/methods/test_describe.py +++ b/pandas/tests/frame/methods/test_describe.py @@ -385,5 +385,11 @@ def test_describe_does_not_raise_error(self): ) result = df.describe() tm.assert_frame_equal(result, expected) - exp_repr = " test\n" "count 2\n" "unique 2\n" "top {'a': '1'}\n" "freq 1" + exp_repr = ( + " test\n" + "count 2\n" + "unique 2\n" + "top {'a': '1'}\n" + "freq 1" + ) assert repr(result) == exp_repr From f232ad971ceaebc7813c96f75154117406435d34 Mon Sep 17 00:00:00 2001 From: lvs1 Date: Thu, 10 Dec 2020 09:18:41 -0800 Subject: [PATCH 3/5] TST: Remove trailing whitespace --- pandas/tests/frame/methods/test_describe.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/tests/frame/methods/test_describe.py b/pandas/tests/frame/methods/test_describe.py index 8d6e0c773ae98..d75fd5e60cee0 100644 --- a/pandas/tests/frame/methods/test_describe.py +++ b/pandas/tests/frame/methods/test_describe.py @@ -386,10 +386,10 @@ def test_describe_does_not_raise_error(self): result = df.describe() tm.assert_frame_equal(result, expected) exp_repr = ( - " test\n" - "count 2\n" - "unique 2\n" - "top {'a': '1'}\n" + " test\n" + "count 2\n" + "unique 2\n" + "top {'a': '1'}\n" "freq 1" ) assert repr(result) == exp_repr From c81561cbe8ec4c5e73122d655d328403d5265e34 Mon Sep 17 00:00:00 2001 From: lvs1 Date: Sun, 17 Jan 2021 21:43:19 -0800 Subject: [PATCH 4/5] Update test naming and remove assertion on repr --- pandas/tests/frame/methods/test_describe.py | 26 +++++++-------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/pandas/tests/frame/methods/test_describe.py b/pandas/tests/frame/methods/test_describe.py index d75fd5e60cee0..15bafb7a835ba 100644 --- a/pandas/tests/frame/methods/test_describe.py +++ b/pandas/tests/frame/methods/test_describe.py @@ -367,6 +367,15 @@ def test_describe_percentiles_integer_idx(self): ) tm.assert_frame_equal(result, expected) + def test_describe_does_not_raise_error_for_dictlike_elements(self): + # GH#32409 + df = DataFrame([{"test": {"a": "1"}}, {"test": {"a": "2"}}]) + expected = DataFrame( + {"test": [2, 2, {"a": "1"}, 1]}, index=["count", "unique", "top", "freq"] + ) + result = df.describe() + tm.assert_frame_equal(result, expected) + @pytest.mark.parametrize("exclude", ["x", "y", ["x", "y"], ["x", "z"]]) def test_describe_when_include_all_exclude_not_allowed(self, exclude): """ @@ -376,20 +385,3 @@ def test_describe_when_include_all_exclude_not_allowed(self, exclude): msg = "exclude must be None when include is 'all'" with pytest.raises(ValueError, match=msg): df.describe(include="all", exclude=exclude) - - def test_describe_does_not_raise_error(self): - # GH#32409 - df = DataFrame([{"test": {"a": "1"}}, {"test": {"a": "2"}}]) - expected = DataFrame( - {"test": [2, 2, {"a": "1"}, 1]}, index=["count", "unique", "top", "freq"] - ) - result = df.describe() - tm.assert_frame_equal(result, expected) - exp_repr = ( - " test\n" - "count 2\n" - "unique 2\n" - "top {'a': '1'}\n" - "freq 1" - ) - assert repr(result) == exp_repr From 4998cbf5f5e8ac27cfd5145d3d6d98c6de08ad03 Mon Sep 17 00:00:00 2001 From: lvs1 Date: Wed, 20 Jan 2021 06:39:36 -0800 Subject: [PATCH 5/5] Update value of expected in dataframe --- pandas/tests/frame/methods/test_describe.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/frame/methods/test_describe.py b/pandas/tests/frame/methods/test_describe.py index 15bafb7a835ba..ed1c3fcce378c 100644 --- a/pandas/tests/frame/methods/test_describe.py +++ b/pandas/tests/frame/methods/test_describe.py @@ -371,7 +371,7 @@ def test_describe_does_not_raise_error_for_dictlike_elements(self): # GH#32409 df = DataFrame([{"test": {"a": "1"}}, {"test": {"a": "2"}}]) expected = DataFrame( - {"test": [2, 2, {"a": "1"}, 1]}, index=["count", "unique", "top", "freq"] + {"test": [2, 2, {"a": "2"}, 1]}, index=["count", "unique", "top", "freq"] ) result = df.describe() tm.assert_frame_equal(result, expected)