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

Function _maybe_get_mask

pandas/core/nanops.py:212–253  ·  view source on GitHub ↗

Compute a mask if and only if necessary. This function will compute a mask iff it is necessary. Otherwise, return the provided mask (potentially None) when a mask does not need to be computed. A mask is never necessary if the values array is of boolean or integer dtypes, a

(
    values: np.ndarray, skipna: bool, mask: npt.NDArray[np.bool_] | None
)

Source from the content-addressed store, hash-verified

210
211
212def _maybe_get_mask(
213 values: np.ndarray, skipna: bool, mask: npt.NDArray[np.bool_] | None
214) -> npt.NDArray[np.bool_] | None:
215 """
216 Compute a mask if and only if necessary.
217
218 This function will compute a mask iff it is necessary. Otherwise,
219 return the provided mask (potentially None) when a mask does not need to be
220 computed.
221
222 A mask is never necessary if the values array is of boolean or integer
223 dtypes, as these are incapable of storing NaNs. If passing a NaN-capable
224 dtype that is interpretable as either boolean or integer data (eg,
225 timedelta64), a mask must be provided.
226
227 If the skipna parameter is False, a new mask will not be computed.
228
229 The mask is computed using isna() by default. Setting invert=True selects
230 notna() as the masking function.
231
232 Parameters
233 ----------
234 values : ndarray
235 input array to potentially compute mask for
236 skipna : bool
237 boolean for whether NaNs should be skipped
238 mask : Optional[ndarray]
239 nan-mask if known
240
241 Returns
242 -------
243 Optional[np.ndarray[bool]]
244 """
245 if mask is None:
246 if values.dtype.kind in "biu":
247 # Boolean data cannot contain nulls, so signal via mask being None
248 return None
249
250 if skipna or values.dtype.kind in "mM":
251 mask = isna(values)
252
253 return mask
254
255
256def _get_values(

Callers 6

_get_valuesFunction · 0.85
nanvarFunction · 0.85
nansemFunction · 0.85
nanskewFunction · 0.85
nankurtFunction · 0.85
nanprodFunction · 0.85

Calls 1

isnaFunction · 0.90

Tested by

no test coverage detected