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

Function _get_values

pandas/core/nanops.py:256–324  ·  view source on GitHub ↗

Utility to get the values view, mask, dtype, dtype_max, and fill_value. If both mask and fill_value/fill_value_typ are not None and skipna is True, the values array will be copied. For input arrays of boolean or integer dtypes, copies will only occur if a precomputed mask, a f

(
    values: np.ndarray,
    skipna: bool,
    fill_value: Any = None,
    fill_value_typ: str | None = None,
    mask: npt.NDArray[np.bool_] | None = None,
)

Source from the content-addressed store, hash-verified

254
255
256def _get_values(
257 values: np.ndarray,
258 skipna: bool,
259 fill_value: Any = None,
260 fill_value_typ: str | None = None,
261 mask: npt.NDArray[np.bool_] | None = None,
262) -> tuple[np.ndarray, npt.NDArray[np.bool_] | None]:
263 """
264 Utility to get the values view, mask, dtype, dtype_max, and fill_value.
265
266 If both mask and fill_value/fill_value_typ are not None and skipna is True,
267 the values array will be copied.
268
269 For input arrays of boolean or integer dtypes, copies will only occur if a
270 precomputed mask, a fill_value/fill_value_typ, and skipna=True are
271 provided.
272
273 Parameters
274 ----------
275 values : ndarray
276 input array to potentially compute mask for
277 skipna : bool
278 boolean for whether NaNs should be skipped
279 fill_value : Any
280 value to fill NaNs with
281 fill_value_typ : str
282 Set to '+inf' or '-inf' to handle dtype-specific infinities
283 mask : Optional[np.ndarray[bool]]
284 nan-mask if known
285
286 Returns
287 -------
288 values : ndarray
289 Potential copy of input value array
290 mask : Optional[ndarray[bool]]
291 Mask for values, if deemed necessary to compute
292 """
293 # In _get_values is only called from within nanops, and in all cases
294 # with scalar fill_value. This guarantee is important for the
295 # np.where call below
296
297 mask = _maybe_get_mask(values, skipna, mask)
298
299 dtype = values.dtype
300
301 datetimelike = False
302 if values.dtype.kind in "mM":
303 # changing timedelta64/datetime64 to int64 needs to happen after
304 # finding `mask` above
305 values = np.asarray(values.view("i8"))
306 datetimelike = True
307
308 if skipna and (mask is not None):
309 # get our fill value (in case we need to provide an alternative
310 # dtype for it)
311 fill_value = _get_fill_value(
312 dtype, fill_value=fill_value, fill_value_typ=fill_value_typ
313 )

Callers 9

nananyFunction · 0.85
nanallFunction · 0.85
nansumFunction · 0.85
nanmeanFunction · 0.85
nanmedianFunction · 0.85
nanstdFunction · 0.85
reductionFunction · 0.85
nanargmaxFunction · 0.85
nanargminFunction · 0.85

Calls 8

_maybe_get_maskFunction · 0.85
_get_fill_valueFunction · 0.85
_na_ok_dtypeFunction · 0.85
viewMethod · 0.45
anyMethod · 0.45
copyMethod · 0.45
putmaskMethod · 0.45
whereMethod · 0.45

Tested by

no test coverage detected