Skip to content

GH:11670: possible bug when calculating mean of DataFrame? #29369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 3, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions pandas/tests/frame/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Copy link
Member

@mroeschke mroeschke Nov 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The C values need to be Decimal objects as the issue described. Could you also update the test name to reflect that?

{"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))
Expand Down