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

Function mode

pandas/core/algorithms.py:996–1039  ·  view source on GitHub ↗

Returns the mode(s) of an array. Parameters ---------- values : array-like Array over which to check for duplicate values. dropna : bool, default True Don't consider counts of NaN/NaT. Returns ------- Union[Tuple[np.ndarray, npt.NDArray[np.bool_]],

(
    values: ArrayLike, dropna: bool = True, mask: npt.NDArray[np.bool_] | None = None
)

Source from the content-addressed store, hash-verified

994
995
996def mode(
997 values: ArrayLike, dropna: bool = True, mask: npt.NDArray[np.bool_] | None = None
998) -> tuple[np.ndarray, npt.NDArray[np.bool_]] | ExtensionArray:
999 """
1000 Returns the mode(s) of an array.
1001
1002 Parameters
1003 ----------
1004 values : array-like
1005 Array over which to check for duplicate values.
1006 dropna : bool, default True
1007 Don't consider counts of NaN/NaT.
1008
1009 Returns
1010 -------
1011 Union[Tuple[np.ndarray, npt.NDArray[np.bool_]], ExtensionArray]
1012 """
1013 values = _ensure_arraylike(values, func_name="mode")
1014 original = values
1015
1016 if needs_i8_conversion(values.dtype):
1017 # Got here with ndarray; dispatch to DatetimeArray/TimedeltaArray.
1018 values = ensure_wrapped_if_datetimelike(values)
1019 values = cast("ExtensionArray", values)
1020 return values._mode(dropna=dropna)
1021
1022 values = _ensure_data(values)
1023
1024 npresult, res_mask = htable.mode(values, dropna=dropna, mask=mask)
1025 if res_mask is None:
1026 res_mask = np.zeros(npresult.shape, dtype=np.bool_)
1027 else:
1028 return npresult, res_mask
1029
1030 try:
1031 npresult = safe_sort(npresult)
1032 except TypeError as err:
1033 warnings.warn(
1034 f"Unable to sort modes: {err}",
1035 stacklevel=find_stack_level(),
1036 )
1037
1038 result = _reconstruct_data(npresult, original.dtype, original)
1039 return result, res_mask
1040
1041
1042def rank(

Callers 2

_modeMethod · 0.90
_modeMethod · 0.90

Calls 9

needs_i8_conversionFunction · 0.90
find_stack_levelFunction · 0.90
_ensure_arraylikeFunction · 0.85
_ensure_dataFunction · 0.85
safe_sortFunction · 0.85
_reconstruct_dataFunction · 0.85
_modeMethod · 0.45
modeMethod · 0.45

Tested by

no test coverage detected