Skip to content

validate_plotting_params

yohou.utils.validate_data.validate_plotting_params(*, kind=None, valid_kinds=None, facet_n_cols=None, n_bins=None, width=None, height=None)

Validate common plotting function parameters.

Parameters

Name Type Description Default
kind str or None

Plot sub-type to validate.

None
valid_kinds set of str or None

Allowed values for kind. Both must be provided together.

None
facet_n_cols int or None

Number of facet columns (must be >= 1).

None
n_bins int or None

Number of histogram bins (must be >= 1).

None
width int or None

Figure width in pixels (must be >= 1).

None
height int or None

Figure height in pixels (must be >= 1).

None

Raises

Type Description
ValueError

If any parameter is invalid.

Examples

>>> from yohou.utils.validate_data import validate_plotting_params
>>> validate_plotting_params(kind="line", valid_kinds={"line", "bar"})
>>> validate_plotting_params(facet_n_cols=2, n_bins=10)

See Also

Source Code

Show/Hide source
def validate_plotting_params(
    *,
    kind: str | None = None,
    valid_kinds: set[str] | None = None,
    facet_n_cols: int | None = None,
    n_bins: int | None = None,
    width: int | None = None,
    height: int | None = None,
) -> None:
    """Validate common plotting function parameters.

    Parameters
    ----------
    kind : str or None
        Plot sub-type to validate.
    valid_kinds : set of str or None
        Allowed values for *kind*.  Both must be provided together.
    facet_n_cols : int or None
        Number of facet columns (must be >= 1).
    n_bins : int or None
        Number of histogram bins (must be >= 1).
    width : int or None
        Figure width in pixels (must be >= 1).
    height : int or None
        Figure height in pixels (must be >= 1).

    Raises
    ------
    ValueError
        If any parameter is invalid.

    Examples
    --------
    >>> from yohou.utils.validate_data import validate_plotting_params
    >>> validate_plotting_params(kind="line", valid_kinds={"line", "bar"})
    >>> validate_plotting_params(facet_n_cols=2, n_bins=10)

    See Also
    --------
    - [`validate_plotting_data`][yohou.utils.validate_data.validate_plotting_data] : Validate DataFrame structure for plotting.

    """
    if kind is not None and valid_kinds is not None and kind not in valid_kinds:
        msg = f"kind must be one of {sorted(valid_kinds)!r}, got {kind!r}"
        raise ValueError(msg)
    if facet_n_cols is not None and facet_n_cols < 1:
        msg = f"facet_n_cols must be >= 1, got {facet_n_cols}"
        raise ValueError(msg)
    if n_bins is not None and n_bins < 1:
        msg = f"n_bins must be >= 1, got {n_bins}"
        raise ValueError(msg)
    if width is not None and width < 1:
        msg = f"width must be >= 1, got {width}"
        raise ValueError(msg)
    if height is not None and height < 1:
        msg = f"height must be >= 1, got {height}"
        raise ValueError(msg)