Skip to content

Commit 41e801c

Browse files
REGR: fix DataFrame reduction with EA columns and numeric_only=True
1 parent 428791c commit 41e801c

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

pandas/core/frame.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -8281,10 +8281,10 @@ def _get_data(axis_matters):
82818281
out_dtype = "bool" if filter_type == "bool" else None
82828282

82838283
def blk_func(values):
8284-
if values.ndim == 1 and not isinstance(values, np.ndarray):
8285-
# we can't pass axis=1
8286-
return op(values, axis=0, skipna=skipna, **kwds)
8287-
return op(values, axis=1, skipna=skipna, **kwds)
8284+
if isinstance(values, ExtensionArray):
8285+
return values._reduce(name, skipna=skipna, **kwds)
8286+
else:
8287+
return op(values, axis=1, skipna=skipna, **kwds)
82888288

82898289
# After possibly _get_data and transposing, we are now in the
82908290
# simple case where we can use BlockManager._reduce

pandas/tests/frame/test_analytics.py

+8
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,14 @@ def test_mean_datetimelike_numeric_only_false(self):
895895
)
896896
tm.assert_series_equal(result, expected)
897897

898+
def test_mean_extensionarray_numeric_only_true(self):
899+
# https://github.com/pandas-dev/pandas/issues/33256
900+
arr = np.random.randint(1000, size=(10, 5))
901+
df = pd.DataFrame(arr, dtype="Int64")
902+
result = df.mean(numeric_only=True)
903+
expected = pd.DataFrame(arr).mean()
904+
tm.assert_series_equal(result, expected)
905+
898906
def test_stats_mixed_type(self, float_string_frame):
899907
# don't blow up
900908
float_string_frame.std(1)

0 commit comments

Comments
 (0)