MCPcopy Create free account
hub / github.com/pydata/xarray / _maybe_null_out

Function _maybe_null_out

xarray/computation/nanops.py:19–38  ·  view source on GitHub ↗

xarray version of pandas.core.nanops._maybe_null_out

(result, axis, mask, min_count=1)

Source from the content-addressed store, hash-verified

17
18
19def _maybe_null_out(result, axis, mask, min_count=1):
20 """
21 xarray version of pandas.core.nanops._maybe_null_out
22 """
23 if axis is not None and getattr(result, "ndim", False):
24 null_mask = (
25 np.take(mask.shape, axis).prod()
26 - duck_array_ops.sum(mask, axis)
27 - min_count
28 ) < 0
29 dtype, fill_value = dtypes.maybe_promote(result.dtype)
30 result = where(null_mask, fill_value, astype(result, dtype))
31
32 elif (dtype := getattr(result, "dtype", None)) and getattr(
33 dtype, "kind", None
34 ) not in {"m", "M"}:
35 null_mask = mask.size - duck_array_ops.sum(mask)
36 result = where(null_mask < min_count, np.nan, result)
37
38 return result
39
40
41def _nan_argminmax_object(func, fill_value, value, axis=None, **kwargs):

Callers 2

nansumFunction · 0.85
nanprodFunction · 0.85

Calls 4

whereFunction · 0.90
astypeFunction · 0.90
prodMethod · 0.45
sumMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…