def subset_lists()

in hypothesis_gufunc/extra/xr.py [0:0]


def subset_lists(L, min_size=0, max_size=None):
    """Strategy to generate a subset of a `list`.

    This should be built in to hypothesis (see hypothesis issue #1115), but was rejected.

    Parameters
    ----------
    L : list
        List of elements we want to get a subset of.
    min_size : int
        Minimum size of the resulting subset list.
    max_size : int or None
        Maximum size of the resulting subset list.

    Returns
    -------
    L : list
        List that is subset of `L` with all unique elements.
    """
    _check_valid_size_interval(min_size, max_size, "subset list size")
    uniq_len = len(set(L))
    order_check("input list size", 0, min_size, uniq_len)

    max_size = uniq_len if max_size is None else min(uniq_len, max_size)

    # Avoid deprecation warning HypothesisDeprecationWarning: sampled_from()
    elements_st = nothing() if uniq_len == 0 else sampled_from(L)

    S = lists(elements=elements_st, min_size=min_size, max_size=max_size, unique=True)
    return S