From f93fa326672383349f661de9233e9390fe9f1aec Mon Sep 17 00:00:00 2001 From: Khor Chean Wei Date: Tue, 31 May 2022 04:50:48 +0800 Subject: [PATCH] Test Case: pd.DataFrame.prob with min_count changes dtype if result contains NaNs (#47170) --- pandas/tests/frame/test_reductions.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pandas/tests/frame/test_reductions.py b/pandas/tests/frame/test_reductions.py index 702faf2f480e8..b4d3d1ae548b5 100644 --- a/pandas/tests/frame/test_reductions.py +++ b/pandas/tests/frame/test_reductions.py @@ -789,12 +789,29 @@ def test_sum_nanops_min_count(self): ) def test_sum_nanops_dtype_min_count(self, float_type, kwargs, expected_result): # GH#46947 - # pass df = DataFrame({"a": [1.0, 2.3, 4.4], "b": [2.2, 3, np.nan]}, dtype=float_type) result = df.sum(**kwargs) expected = Series(expected_result).astype(float_type) tm.assert_series_equal(result, expected) + @pytest.mark.parametrize("float_type", ["float16", "float32", "float64"]) + @pytest.mark.parametrize( + "kwargs, expected_result", + [ + ({"axis": 1, "min_count": 2}, [2.0, 4.0, np.NaN]), + ({"axis": 1, "min_count": 3}, [np.NaN, np.NaN, np.NaN]), + ({"axis": 1, "skipna": False}, [2.0, 4.0, np.NaN]), + ], + ) + def test_prod_nanops_dtype_min_count(self, float_type, kwargs, expected_result): + # GH#46947 + df = DataFrame( + {"a": [1.0, 2.0, 4.4], "b": [2.0, 2.0, np.nan]}, dtype=float_type + ) + result = df.prod(**kwargs) + expected = Series(expected_result).astype(float_type) + tm.assert_series_equal(result, expected) + def test_sum_object(self, float_frame): values = float_frame.values.astype(int) frame = DataFrame(values, index=float_frame.index, columns=float_frame.columns)