(values, axis=None, **kwargs)
| 177 | |
| 178 | def _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) |
no test coverage detected