pola-rs/polars · error · InvalidArgument

`null_probability` should be between 0.0 and 1.0, got {prob!

Error message

`null_probability` should be between 0.0 and 1.0, got {prob!r}

What it means

Validation inside the deprecated null_probability handling of the hypothesis testing strategies: each probability (global or per-column) must lie in [0.0, 1.0] since it is converted to an allow_null boolean. Any out-of-range float triggers this InvalidArgument. Prefer the newer allow_null parameter.

Source

Thrown at py-polars/src/polars/testing/parametric/strategies/core.py:610

    def __post_init__(self) -> None:
        if self.null_probability is not None:
            self.allow_null = _handle_null_probability_deprecation(  # type: ignore[assignment]
                self.null_probability
            )


def _handle_null_probability_deprecation(
    null_probability: float | Mapping[str, float],
) -> bool | dict[str, bool]:
    issue_deprecation_warning(
        "`null_probability` is deprecated. Use `allow_null` instead.",
        version="0.20.26",
    )

    def prob_to_bool(prob: float) -> bool:
        if not (0.0 <= prob <= 1.0):
            msg = f"`null_probability` should be between 0.0 and 1.0, got {prob!r}"
            raise InvalidArgument(msg)

        return bool(prob)

    if isinstance(null_probability, Mapping):
        return {col: prob_to_bool(prob) for col, prob in null_probability.items()}
    else:
        return prob_to_bool(null_probability)

View on GitHub (pinned to 9b5d73fd00)

Solutions

  1. Pass a probability in the range [0.0, 1.0] for `null_probability`.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at py-polars/src/polars/testing/parametric/strategies/core.py:610 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of pola-rs/polars@9b5d73fd00 (2026-08-19). Data as JSON: /api/errors/d4abde0b7e060fff. Report an issue: GitHub.