From b60a7d6a9a03fb27bbba62100b49c33717991811 Mon Sep 17 00:00:00 2001 From: pv8493013j Date: Sat, 2 Nov 2019 17:37:05 +0000 Subject: [PATCH 1/5] add test for mean with mixed df --- pandas/tests/frame/test_analytics.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index e99208ac78e15..3ab64c60afce2 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -1075,6 +1075,29 @@ def test_mean_excludeds_datetimes(self, tz): expected = pd.Series() tm.assert_series_equal(result, expected) + def test_mean_mixed_string_float(self): + # GH 11670 + # possible bug when calculating mean of DataFrame? + + d = [ + {'A': 2, 'B': None, 'C': 628.00}, + {'A': 1, 'B': None, 'C': 383.00}, + {'A': 3, 'B': None, 'C': 651.00}, + {'A': 2, 'B': None, 'C': 575.00}, + {'A': 4, 'B': None, 'C': 1114.00}, + {'A': 1, 'B': 'TEST', 'C': 241.00}, + {'A': 2, 'B': None, 'C': 572.00}, + {'A': 4, 'B': None, 'C': 609.00}, + {'A': 3, 'B': None, 'C': 820.00}, + {'A': 5, 'B': None, 'C': 1223.00} + ] + + df = pd.DataFrame(d) + + result = df.mean() + expected = pd.Series([2.7, 681.6], index=["A", "C"]) + tm.assert_series_equal(result, expected) + def test_var_std(self, datetime_frame): result = datetime_frame.std(ddof=4) expected = datetime_frame.apply(lambda x: x.std(ddof=4)) From 64c720bede46e026e9dd1d602aad0114d3876de4 Mon Sep 17 00:00:00 2001 From: pv8493013j Date: Sat, 2 Nov 2019 17:38:18 +0000 Subject: [PATCH 2/5] improved with black --- pandas/tests/frame/test_analytics.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index 3ab64c60afce2..7cbe3ec8a5171 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -1080,16 +1080,16 @@ def test_mean_mixed_string_float(self): # possible bug when calculating mean of DataFrame? d = [ - {'A': 2, 'B': None, 'C': 628.00}, - {'A': 1, 'B': None, 'C': 383.00}, - {'A': 3, 'B': None, 'C': 651.00}, - {'A': 2, 'B': None, 'C': 575.00}, - {'A': 4, 'B': None, 'C': 1114.00}, - {'A': 1, 'B': 'TEST', 'C': 241.00}, - {'A': 2, 'B': None, 'C': 572.00}, - {'A': 4, 'B': None, 'C': 609.00}, - {'A': 3, 'B': None, 'C': 820.00}, - {'A': 5, 'B': None, 'C': 1223.00} + {"A": 2, "B": None, "C": 628.00}, + {"A": 1, "B": None, "C": 383.00}, + {"A": 3, "B": None, "C": 651.00}, + {"A": 2, "B": None, "C": 575.00}, + {"A": 4, "B": None, "C": 1114.00}, + {"A": 1, "B": "TEST", "C": 241.00}, + {"A": 2, "B": None, "C": 572.00}, + {"A": 4, "B": None, "C": 609.00}, + {"A": 3, "B": None, "C": 820.00}, + {"A": 5, "B": None, "C": 1223.00}, ] df = pd.DataFrame(d) From 20f5f8bf938d1422640989fde10f24bd46871861 Mon Sep 17 00:00:00 2001 From: pv8493013j Date: Sun, 3 Nov 2019 12:14:22 +0000 Subject: [PATCH 3/5] changed float to decimal for test --- pandas/tests/frame/test_analytics.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index 7cbe3ec8a5171..d46cf8abd8d9c 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -2,6 +2,7 @@ import operator from string import ascii_lowercase import warnings +from decimal import Decimal import numpy as np import pytest @@ -1075,21 +1076,21 @@ def test_mean_excludeds_datetimes(self, tz): expected = pd.Series() tm.assert_series_equal(result, expected) - def test_mean_mixed_string_float(self): + def test_mean_mixed_string_decimal(self): # GH 11670 # possible bug when calculating mean of DataFrame? d = [ - {"A": 2, "B": None, "C": 628.00}, - {"A": 1, "B": None, "C": 383.00}, - {"A": 3, "B": None, "C": 651.00}, - {"A": 2, "B": None, "C": 575.00}, - {"A": 4, "B": None, "C": 1114.00}, - {"A": 1, "B": "TEST", "C": 241.00}, - {"A": 2, "B": None, "C": 572.00}, - {"A": 4, "B": None, "C": 609.00}, - {"A": 3, "B": None, "C": 820.00}, - {"A": 5, "B": None, "C": 1223.00}, + {"A": 2, "B": None, "C": Decimal(628.00)}, + {"A": 1, "B": None, "C": Decimal(383.00)}, + {"A": 3, "B": None, "C": Decimal(651.00)}, + {"A": 2, "B": None, "C": Decimal(575.00)}, + {"A": 4, "B": None, "C": Decimal(1114.00)}, + {"A": 1, "B": "TEST", "C": Decimal(241.00)}, + {"A": 2, "B": None, "C": Decimal(572.00)}, + {"A": 4, "B": None, "C": Decimal(609.00)}, + {"A": 3, "B": None, "C": Decimal(820.00)}, + {"A": 5, "B": None, "C": Decimal(1223.00)}, ] df = pd.DataFrame(d) From 792c14518ac0035219b0f149afa43b7125205427 Mon Sep 17 00:00:00 2001 From: pv8493013j Date: Sun, 3 Nov 2019 12:18:09 +0000 Subject: [PATCH 4/5] formatting --- pandas/tests/frame/test_analytics.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index d46cf8abd8d9c..18b4f195436f3 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -1081,16 +1081,16 @@ def test_mean_mixed_string_decimal(self): # possible bug when calculating mean of DataFrame? d = [ - {"A": 2, "B": None, "C": Decimal(628.00)}, - {"A": 1, "B": None, "C": Decimal(383.00)}, - {"A": 3, "B": None, "C": Decimal(651.00)}, - {"A": 2, "B": None, "C": Decimal(575.00)}, - {"A": 4, "B": None, "C": Decimal(1114.00)}, - {"A": 1, "B": "TEST", "C": Decimal(241.00)}, - {"A": 2, "B": None, "C": Decimal(572.00)}, - {"A": 4, "B": None, "C": Decimal(609.00)}, - {"A": 3, "B": None, "C": Decimal(820.00)}, - {"A": 5, "B": None, "C": Decimal(1223.00)}, + {"A": 2, "B": None, "C": Decimal("628.00")}, + {"A": 1, "B": None, "C": Decimal("383.00")}, + {"A": 3, "B": None, "C": Decimal("651.00")}, + {"A": 2, "B": None, "C": Decimal("575.00")}, + {"A": 4, "B": None, "C": Decimal("1114.00")}, + {"A": 1, "B": "TEST", "C": Decimal("241.00")}, + {"A": 2, "B": None, "C": Decimal("572.00")}, + {"A": 4, "B": None, "C": Decimal("609.00")}, + {"A": 3, "B": None, "C": Decimal("820.00")}, + {"A": 5, "B": None, "C": Decimal("1223.00")}, ] df = pd.DataFrame(d) From e74dd116f5ea97d9f1587588dcfadafe6b3e93e9 Mon Sep 17 00:00:00 2001 From: pv8493013j Date: Sun, 3 Nov 2019 14:09:04 +0000 Subject: [PATCH 5/5] correct import order --- pandas/tests/frame/test_analytics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index 18b4f195436f3..f694689fa9dfb 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -1,8 +1,8 @@ from datetime import timedelta +from decimal import Decimal import operator from string import ascii_lowercase import warnings -from decimal import Decimal import numpy as np import pytest