diff --git a/pandas/core/frame.py b/pandas/core/frame.py index e48620a854edb..a50000d31d3d4 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -11850,6 +11850,14 @@ def _reduce( if axis is not None: axis = self._get_axis_number(axis) + if axis == 0: + data = self._get_numeric_data() if numeric_only else self + results = {} + for col in data.columns: + ser = data[col] + results[col] = getattr(ser, name)(skipna=skipna, **kwds) + return self._constructor_sliced(results) + def func(values: np.ndarray): # We only use this in the case that operates on self.values return op(values, axis=axis, skipna=skipna, **kwds) diff --git a/pandas/tests/frame/test_reductions.py b/pandas/tests/frame/test_reductions.py index cc23c292b66dc..50ae3e0066734 100644 --- a/pandas/tests/frame/test_reductions.py +++ b/pandas/tests/frame/test_reductions.py @@ -221,6 +221,20 @@ def float_frame_with_na(): return df +def test_mixed_reduction_nan_vs_NA(): + df = DataFrame( + { + "B": [1, None, 3], + "C": pd.array([1, None, 3], dtype="Int64"), + } + ) + result = df.skew() + assert np.isnan(result["B"]) + assert isna(result["C"]) and type(result["C"]).__name__ == "NAType" + result_B = df[["B"]].skew() + assert np.isnan(result_B["B"]) + + class TestDataFrameAnalytics: # --------------------------------------------------------------------- # Reductions