_validate_weights

Signature

_validate_weights(
    x: FloatVector,
    w: ArrayLike | None,
) -> FloatVector | None

What problem it solves

Centralizes validation of the weights used in weighted statistics.

Input contract

  • If w is None, it returns None and the caller falls back to the unweighted case.

  • If w is provided, it is first converted with _as_float_vector.

  • w must have the same shape as x.

  • Each weight must be strictly positive.

  • The sum of the weights must also be strictly positive and finite.

Where it is used

Failure modes

  • ValueError if w does not have the same shape as x

  • ValueError if it contains zeros, negative values, NaN values, or infinities

  • ValueError if the sum of the weights is not positive

Why it stays private

It enforces a shared convention for weights without introducing an extra function into the public API.