(
self,
op,
name: str,
*,
axis: Axis = 0,
skipna: bool = True,
numeric_only: bool = False,
filter_type=None,
**kwds,
)
| 13536 | return result.astype("int64").__finalize__(self, method="count") |
| 13537 | |
| 13538 | def _reduce( |
| 13539 | self, |
| 13540 | op, |
| 13541 | name: str, |
| 13542 | *, |
| 13543 | axis: Axis = 0, |
| 13544 | skipna: bool = True, |
| 13545 | numeric_only: bool = False, |
| 13546 | filter_type=None, |
| 13547 | **kwds, |
| 13548 | ): |
| 13549 | assert filter_type is None or filter_type == "bool", filter_type |
| 13550 | out_dtype = "bool" if filter_type == "bool" else None |
| 13551 | |
| 13552 | if axis is not None: |
| 13553 | axis = self._get_axis_number(axis) |
| 13554 | |
| 13555 | def func(values: np.ndarray): |
| 13556 | # We only use this in the case that operates on self.values |
| 13557 | return op(values, axis=axis, skipna=skipna, **kwds) |
| 13558 | |
| 13559 | def blk_func(values, axis: Axis = 1): |
| 13560 | if isinstance(values, ExtensionArray): |
| 13561 | if not is_1d_only_ea_dtype(values.dtype): |
| 13562 | return values._reduce(name, axis=1, skipna=skipna, **kwds) |
| 13563 | return values._reduce(name, skipna=skipna, keepdims=True, **kwds) |
| 13564 | else: |
| 13565 | return op(values, axis=axis, skipna=skipna, **kwds) |
| 13566 | |
| 13567 | def _get_data() -> DataFrame: |
| 13568 | if filter_type is None: |
| 13569 | data = self._get_numeric_data() |
| 13570 | else: |
| 13571 | # GH#25101, GH#24434 |
| 13572 | assert filter_type == "bool" |
| 13573 | data = self._get_bool_data() |
| 13574 | return data |
| 13575 | |
| 13576 | # Case with EAs see GH#35881 |
| 13577 | df = self |
| 13578 | if numeric_only: |
| 13579 | df = _get_data() |
| 13580 | if axis is None: |
| 13581 | dtype = find_common_type([block.values.dtype for block in df._mgr.blocks]) |
| 13582 | if isinstance(dtype, ExtensionDtype): |
| 13583 | df = df.astype(dtype) |
| 13584 | arr = concat_compat(list(df._iter_column_arrays())) |
| 13585 | return arr._reduce(name, skipna=skipna, keepdims=False, **kwds) |
| 13586 | return maybe_unbox_numpy_scalar(func(df.values)) |
| 13587 | elif axis == 1: |
| 13588 | if len(df.index) == 0: |
| 13589 | # Taking a transpose would result in no columns, losing the dtype. |
| 13590 | # In the empty case, reducing along axis 0 or 1 gives the same |
| 13591 | # result dtype, so reduce with axis=0 and ignore values |
| 13592 | result = df._reduce( |
| 13593 | op, |
| 13594 | name, |
| 13595 | axis=0, |
no test coverage detected