Repository: scikit-learn/scikit-learn
File: sklearn/ensemble/_bagging.py (Python)

Code before:

    Returns
    -------
    n_samples_bootstrap : int
        The total number of samples to draw for the bootstrap sample.
    """
    if max_samples is None:
        return n_samples
    elif isinstance(max_samples, Integral):
        return max_samples
    elif not isinstance(max_samples, Real):
        raise ValueError(
            f"max_samples must be None, int or float got {type(max_samples)}"
        )

    if sample_weight is None:
        n_samples_total = n_samples
        n_samples_total_msg = f"the number of samples is {n_samples_total} "
    else:
        n_samples_total = sample_weight.sum()
        n_samples_total_msg = f"the total sum of sample weights is {n_samples_total} "

    # max_samples Real fractional value relative to n_samples_total
    n_samples_bootstrap = max(int(max_samples * n_samples_total), 1)
    # raise warning if n_samples_bootstrap small (< 10)
    if n_samples_bootstrap < 10:
        warn(
            f"Using the fractional value {max_samples=} when {n_samples_total_msg}"
            f"results in a low number ({n_samples_bootstrap}) of bootstrap samples. "
            "We recommend passing `max_samples` as an integer."
        )
    return n_samples_bootstrap


def _generate_indices(random_state, bootstrap, n_population, n_samples):
    """Draw randomly sampled indices."""
    # Draw sample indices
    if bootstrap:
        indices = random_state.randint(0, n_population, n_samples)
    else:
        indices = sample_without_replacement(
            n_population, n_samples, random_state=random_state
        )

    return indices


def _generate_bagging_indices(
    random_state,
    bootstrap_features,
    bootstrap_samples,

Review comment (suggestion):
```suggestion
    if n_samples_bootstrap < max(10, n_samples ** (1/3)):
```

I find that hard to believe someone would want to sample less than `cubic_root(n_samples)`.
I mean, if you made the effort to load and preprocess 1M rows, you probably want to use more than 100 samples in your model.
I even hesitate with `sqrt(n_samples)`: but maybe that would make this warning too frequent? Maybe a compromise at `n_samples ** 0.4`? 😅 

Code after:
        set to a float or integer value. When keeping the `max_samples=None` default
        value, the equivalence between fitting with integer weighted data points or
        integer repeated data points is no longer guaranteed because the effective
        bootstrap size is no longer guaranteed to be equivalent.

    Returns
    -------
    n_samples_bootstrap : int
        The total number of samples to draw for the bootstrap sample.
    """
    if max_samples is None:
        return n_samples
    elif isinstance(max_samples, Integral):
        return max_samples

    if sample_weight is None:
        weighted_n_samples = n_samples
        weighted_n_samples_msg = f"the number of samples is {weighted_n_samples} "
    else:
        weighted_n_samples = sample_weight.sum()
        weighted_n_samples_msg = (
            f"the total sum of sample weights is {weighted_n_samples} "
        )

    # max_samples Real fractional value relative to weighted_n_samples
    n_samples_bootstrap = max(int(max_samples * weighted_n_samples), 1)
    # Warn when number of bootstrap samples is suspiciously small
    # This heuristic for "suspiciously small" might be adapted if found
    # unsuitable in practice
    if n_samples_bootstrap < max(10, n_samples ** (1 / 3)):
        warn(
            f"Using the fractional value {max_samples=} when {weighted_n_samples_msg}"
            f"results in a low number ({n_samples_bootstrap}) of bootstrap samples. "
            "We recommend passing `max_samples` as an integer instead."
        )
    return n_samples_bootstrap


def _generate_indices(random_state, bootstrap, n_population, n_samples):
    """Draw randomly sampled indices."""
    # Draw sample indices
    if bootstrap:
        indices = random_state.randint(0, n_population, n_samples)
    else:
        indices = sample_without_replacement(
            n_population, n_samples, random_state=random_state
        )

    return indices