MCPcopy
hub / github.com/pandas-dev/pandas / _reduce

Method _reduce

pandas/core/series.py:7455–7497  ·  view source on GitHub ↗

Perform a reduction operation. If we have an ndarray as a value, then simply perform the operation, otherwise delegate to the object.

(
        self,
        op,
        # error: Variable "pandas.core.series.Series.str" is not valid as a type
        name: str,  # type: ignore[valid-type]
        *,
        axis: Axis = 0,
        skipna: bool = True,
        numeric_only: bool = False,
        filter_type=None,
        **kwds,
    )

Source from the content-addressed store, hash-verified

7453 # Reductions
7454
7455 def _reduce(
7456 self,
7457 op,
7458 # error: Variable "pandas.core.series.Series.str" is not valid as a type
7459 name: str, # type: ignore[valid-type]
7460 *,
7461 axis: Axis = 0,
7462 skipna: bool = True,
7463 numeric_only: bool = False,
7464 filter_type=None,
7465 **kwds,
7466 ):
7467 """
7468 Perform a reduction operation.
7469
7470 If we have an ndarray as a value, then simply perform the operation,
7471 otherwise delegate to the object.
7472 """
7473 delegate = self._values
7474
7475 if axis is not None:
7476 self._get_axis_number(axis)
7477
7478 if isinstance(delegate, ExtensionArray):
7479 # dispatch to ExtensionArray interface
7480 result = delegate._reduce(name, skipna=skipna, **kwds)
7481
7482 else:
7483 # dispatch to numpy arrays
7484 if numeric_only and self.dtype.kind not in "iufcb":
7485 # i.e. not is_numeric_dtype(self.dtype)
7486 kwd_name = "numeric_only"
7487 if name in ["any", "all"]:
7488 kwd_name = "bool_only"
7489 # GH#47500 - change to TypeError to match other methods
7490 raise TypeError(
7491 f"Series.{name} does not allow {kwd_name}={numeric_only} "
7492 "with non-numeric dtypes."
7493 )
7494 result = op(delegate, skipna=skipna, **kwds)
7495
7496 result = maybe_unbox_numpy_scalar(result)
7497 return result
7498
7499 # error: Signature of "any" incompatible with supertype "NDFrame"
7500 def any( # type: ignore[override]

Callers 7

anyMethod · 0.95
allMethod · 0.95
_validate_keyMethod · 0.45
_logical_funcMethod · 0.45
_stat_function_ddofMethod · 0.45
_stat_functionMethod · 0.45

Calls 3

maybe_unbox_numpy_scalarFunction · 0.90
opFunction · 0.85
_get_axis_numberMethod · 0.80

Tested by

no test coverage detected