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

Function nanskew

pandas/core/nanops.py:1222–1306  ·  view source on GitHub ↗

Compute the sample skewness. The statistic computed here is the adjusted Fisher-Pearson standardized moment coefficient G1. The algorithm computes this coefficient directly from the second and third central moment. Parameters ---------- values : ndarray axis : int,

(
    values: np.ndarray,
    *,
    axis: AxisInt | None = None,
    skipna: bool = True,
    mask: npt.NDArray[np.bool_] | None = None,
)

Source from the content-addressed store, hash-verified

1220@disallow("M8", "m8")
1221@maybe_operate_rowwise
1222def nanskew(
1223 values: np.ndarray,
1224 *,
1225 axis: AxisInt | None = None,
1226 skipna: bool = True,
1227 mask: npt.NDArray[np.bool_] | None = None,
1228) -> float:
1229 """
1230 Compute the sample skewness.
1231
1232 The statistic computed here is the adjusted Fisher-Pearson standardized
1233 moment coefficient G1. The algorithm computes this coefficient directly
1234 from the second and third central moment.
1235
1236 Parameters
1237 ----------
1238 values : ndarray
1239 axis : int, optional
1240 skipna : bool, default True
1241 mask : ndarray[bool], optional
1242 nan-mask if known
1243
1244 Returns
1245 -------
1246 result : float64
1247 Unless input is a float array, in which case use the same
1248 precision as the input array.
1249
1250 Examples
1251 --------
1252 >>> from pandas.core import nanops
1253 >>> s = pd.Series([1, np.nan, 1, 2])
1254 >>> nanops.nanskew(s.values)
1255 np.float64(1.7320508075688787)
1256 """
1257 mask = _maybe_get_mask(values, skipna, mask)
1258 if values.dtype.kind != "f":
1259 values = values.astype("f8")
1260 count = _get_counts(values.shape, mask, axis)
1261 else:
1262 count = _get_counts(values.shape, mask, axis, dtype=values.dtype)
1263
1264 if skipna and mask is not None:
1265 values = values.copy()
1266 np.putmask(values, mask, 0)
1267 elif not skipna and mask is not None and mask.any():
1268 return np.nan
1269
1270 with np.errstate(invalid="ignore", divide="ignore"):
1271 mean = values.sum(axis, dtype=np.float64) / count
1272 if axis is not None:
1273 mean = np.expand_dims(mean, axis)
1274
1275 adjusted = values - mean
1276 if skipna and mask is not None:
1277 np.putmask(adjusted, mask, 0)
1278 adjusted2 = adjusted**2
1279 adjusted3 = adjusted2 * adjusted

Callers

nothing calls this directly

Calls 12

_maybe_get_maskFunction · 0.85
_get_countsFunction · 0.85
_zero_out_fperrFunction · 0.85
absMethod · 0.80
astypeMethod · 0.45
copyMethod · 0.45
putmaskMethod · 0.45
anyMethod · 0.45
sumMethod · 0.45
maxMethod · 0.45
whereMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected