Skip to content

Commit f93fa32

Browse files
Khor Chean Weiyehoshuadimarsky
Khor Chean Wei
authored andcommitted
Test Case: pd.DataFrame.prob with min_count changes dtype if result contains NaNs (pandas-dev#47170)
1 parent b568848 commit f93fa32

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

pandas/tests/frame/test_reductions.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -789,12 +789,29 @@ def test_sum_nanops_min_count(self):
789789
)
790790
def test_sum_nanops_dtype_min_count(self, float_type, kwargs, expected_result):
791791
# GH#46947
792-
# pass
793792
df = DataFrame({"a": [1.0, 2.3, 4.4], "b": [2.2, 3, np.nan]}, dtype=float_type)
794793
result = df.sum(**kwargs)
795794
expected = Series(expected_result).astype(float_type)
796795
tm.assert_series_equal(result, expected)
797796

797+
@pytest.mark.parametrize("float_type", ["float16", "float32", "float64"])
798+
@pytest.mark.parametrize(
799+
"kwargs, expected_result",
800+
[
801+
({"axis": 1, "min_count": 2}, [2.0, 4.0, np.NaN]),
802+
({"axis": 1, "min_count": 3}, [np.NaN, np.NaN, np.NaN]),
803+
({"axis": 1, "skipna": False}, [2.0, 4.0, np.NaN]),
804+
],
805+
)
806+
def test_prod_nanops_dtype_min_count(self, float_type, kwargs, expected_result):
807+
# GH#46947
808+
df = DataFrame(
809+
{"a": [1.0, 2.0, 4.4], "b": [2.0, 2.0, np.nan]}, dtype=float_type
810+
)
811+
result = df.prod(**kwargs)
812+
expected = Series(expected_result).astype(float_type)
813+
tm.assert_series_equal(result, expected)
814+
798815
def test_sum_object(self, float_frame):
799816
values = float_frame.values.astype(int)
800817
frame = DataFrame(values, index=float_frame.index, columns=float_frame.columns)

0 commit comments

Comments
 (0)