MCPcopy
hub / github.com/pydata/xarray / f

Function f

xarray/core/nputils.py:179–244  ·  view source on GitHub ↗
(values, axis=None, **kwargs)

Source from the content-addressed store, hash-verified

177
178def _create_method(name, npmodule=np) -> Callable:
179 def f(values, axis=None, **kwargs):
180 dtype = kwargs.get("dtype")
181 bn_func = getattr(bn, name, None)
182
183 xp = get_array_namespace(values)
184 if xp is not np:
185 func = getattr(xp, name, None)
186 if func is not None:
187 return func(values, axis=axis, **kwargs)
188 if (
189 module_available("numbagg")
190 and OPTIONS["use_numbagg"]
191 and isinstance(values, np.ndarray)
192 # numbagg<0.7.0 uses ddof=1 only, but numpy uses ddof=0 by default
193 and (
194 pycompat.mod_version("numbagg") >= Version("0.7.0")
195 or ("var" not in name and "std" not in name)
196 or kwargs.get("ddof", 0) == 1
197 )
198 # TODO: bool?
199 and values.dtype.kind in "uif"
200 # and values.dtype.isnative
201 and (dtype is None or np.dtype(dtype) == values.dtype)
202 # numbagg.nanquantile only available after 0.8.0 and with linear method
203 and (
204 name != "nanquantile"
205 or (
206 pycompat.mod_version("numbagg") >= Version("0.8.0")
207 and kwargs.get("method", "linear") == "linear"
208 )
209 )
210 ):
211 import numbagg # type: ignore[import-not-found, unused-ignore]
212
213 nba_func = getattr(numbagg, name, None)
214 if nba_func is not None:
215 # numbagg does not use dtype
216 kwargs.pop("dtype", None)
217 # prior to 0.7.0, numbagg did not support ddof; we ensure it's limited
218 # to ddof=1 above.
219 if pycompat.mod_version("numbagg") < Version("0.7.0"):
220 kwargs.pop("ddof", None)
221 if name == "nanquantile":
222 kwargs["quantiles"] = kwargs.pop("q")
223 kwargs.pop("method", None)
224 return nba_func(values, axis=axis, **kwargs)
225 if (
226 _BOTTLENECK_AVAILABLE
227 and OPTIONS["use_bottleneck"]
228 and isinstance(values, np.ndarray)
229 and bn_func is not None
230 and not isinstance(axis, tuple)
231 and values.dtype.kind in "uifc"
232 and values.dtype.isnative
233 and (dtype is None or np.dtype(dtype) == values.dtype)
234 ):
235 # bottleneck does not take care dtype, min_count
236 kwargs.pop("dtype", None)

Callers 15

_unary_opMethod · 0.70
_binary_opMethod · 0.70
apply_over_bothMethod · 0.70
_calculate_binary_opMethod · 0.70
pipeMethod · 0.70
reduceMethod · 0.70
func_interpolate_naFunction · 0.70
pipeMethod · 0.70
_unary_opMethod · 0.70
_binary_opMethod · 0.70
_inplace_binary_opMethod · 0.70
_unary_opMethod · 0.70

Calls 5

get_array_namespaceFunction · 0.90
module_availableFunction · 0.90
funcFunction · 0.50
getMethod · 0.45
dtypeMethod · 0.45

Tested by

no test coverage detected