Skip to content

Commit 21aee0d

Browse files
fix numeric_only for EAs
1 parent a9ca0fa commit 21aee0d

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7940,7 +7940,7 @@ def blk_func(values):
79407940

79417941
# After possibly _get_data and transposing, we are now in the
79427942
# simple case where we can use BlockManager._reduce
7943-
res = df._data.reduce(blk_func)
7943+
res = df._data.reduce(blk_func, name, skipna, **kwds)
79447944
assert isinstance(res, dict)
79457945
if len(res):
79467946
assert len(res) == max(list(res.keys())) + 1, res.keys()

pandas/core/internals/managers.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -349,24 +349,27 @@ def _verify_integrity(self) -> None:
349349
f"tot_items: {tot_items}"
350350
)
351351

352-
def reduce(self, func, *args, **kwargs):
352+
def reduce(self, func, name, skipna=True, **kwds):
353353
# If 2D, we assume that we're operating column-wise
354354
if self.ndim == 1:
355355
# we'll be returning a scalar
356356
blk = self.blocks[0]
357-
return func(blk.values, *args, **kwargs)
357+
return func(blk.values)
358358

359359
res = {}
360360
for blk in self.blocks:
361-
bres = func(blk.values, *args, **kwargs)
361+
if isinstance(blk, ExtensionBlock):
362+
bres = blk.values._reduce(name, skipna=skipna, **kwds)
363+
else:
364+
bres = func(blk.values)
362365

363366
if np.ndim(bres) == 0:
364367
# EA
365368
assert blk.shape[0] == 1
366369
new_res = zip(blk.mgr_locs.as_array, [bres])
367370
else:
368371
assert bres.ndim == 1, bres.shape
369-
assert blk.shape[0] == len(bres), (blk.shape, bres.shape, args, kwargs)
372+
assert blk.shape[0] == len(bres), (blk.shape, bres.shape)
370373
new_res = zip(blk.mgr_locs.as_array, bres)
371374

372375
nr = dict(new_res)

0 commit comments

Comments
 (0)