Skip to content

Commit c6e81bc

Browse files
committed
added parameterized test for empty/all-na series mean
1 parent 9b40adb commit c6e81bc

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

pandas/tests/reductions/test_reductions.py

+17-10
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,23 @@ def test_empty_multi(self, method, unit):
679679
expected = Series([1, np.nan], index=["a", "b"])
680680
tm.assert_series_equal(result, expected)
681681

682+
@pytest.mark.parametrize("method", ["mean"])
683+
@pytest.mark.parametrize("dtype", ["float64", "Int64", "boolean", "object"])
684+
def test_ops_consistency_mean(self, method, dtype):
685+
686+
# GH#34814
687+
# consistency for nullable dtypes on empty or ALL-NA mean
688+
689+
# empty series
690+
eser = Series([], dtype=dtype)
691+
result = getattr(eser, method)()
692+
assert result is pd.NA
693+
694+
# ALL-NA series
695+
nser = Series([np.nan], dtype=dtype)
696+
result = getattr(nser, method)()
697+
assert result is pd.NA
698+
682699
@pytest.mark.parametrize("method", ["mean", "median", "std", "var"])
683700
def test_ops_consistency_on_empty(self, method):
684701

@@ -689,16 +706,6 @@ def test_ops_consistency_on_empty(self, method):
689706
result = getattr(Series(dtype=float), method)()
690707
assert pd.isna(result)
691708

692-
# Nullable dtype on mean
693-
eser = Series([], dtype="Int64")
694-
nser = Series([np.nan], dtype="Int64")
695-
if method == "mean":
696-
result = getattr(eser, method)()
697-
assert result is pd.NA
698-
699-
result = getattr(nser, method)()
700-
assert result is pd.NA
701-
702709
# timedelta64[ns]
703710
tdser = Series([], dtype="m8[ns]")
704711
if method == "var":

0 commit comments

Comments
 (0)