Repository: scikit-learn/scikit-learn
File: sklearn/metrics/pairwise.py (Python)

Code before:
    for sl in slices:
        if sl.start == 0 and sl.stop == n_samples_X:
            X_chunk = X  # enable optimised paths for X is Y
        else:
            X_chunk = X[sl]
        D_chunk = pairwise_distances(X_chunk, Y, metric=metric, n_jobs=n_jobs, **kwds)
        if (X is Y or Y is None) and PAIRWISE_DISTANCE_FUNCTIONS.get(
            metric, None
        ) is euclidean_distances:
            # zeroing diagonal, taking care of aliases of "euclidean",
            # i.e. "l2"
            D_chunk.flat[sl.start :: _num_samples(X) + 1] = 0
        if reduce_func is not None:
            chunk_size = D_chunk.shape[0]
            D_chunk = reduce_func(D_chunk, sl.start)
            _check_chunk_size(D_chunk, chunk_size)
        yield D_chunk


@validate_params(
    {
        "X": ["array-like", "sparse matrix"],
        "Y": ["array-like", "sparse matrix", None],
        "metric": [StrOptions(set(_VALID_METRICS) | {"precomputed"}), callable],
        "n_jobs": [Integral, None],
        "ensure_all_finite": ["boolean", StrOptions({"allow-nan"}), Hidden(None)],
    },
    prefer_skip_nested_validation=True,
)
def pairwise_distances(
    X,
    Y=None,
    metric="euclidean",
    *,
    n_jobs=None,
    ensure_all_finite=True,
    **kwds,
):
    """Compute the distance matrix from a feature array X and optional Y.

    This function takes one or two feature arrays or a distance matrix, and returns
    a distance matrix.

    - If `X` is a feature array, of shape (n_samples_X, n_features), and:

      - `Y` is `None` and `metric` is not 'precomputed', the pairwise distances
        between `X` and itself are returned.
      - `Y` is a feature array of shape (n_samples_Y, n_features), the pairwise
        distances between `X` and `Y` is returned.

    - If `X` is a distance matrix, of shape (n_samples_X, n_samples_X), `metric`

Review comment (suggestion):
we can remove None without deprecation. It was only added temporary during the deprecation cycle
```suggestion
        "ensure_all_finite": ["boolean", StrOptions({"allow-nan"})],
```

Code after:
    for sl in slices:
        if sl.start == 0 and sl.stop == n_samples_X:
            X_chunk = X  # enable optimised paths for X is Y
        else:
            X_chunk = X[sl]
        D_chunk = pairwise_distances(X_chunk, Y, metric=metric, n_jobs=n_jobs, **kwds)
        if (X is Y or Y is None) and PAIRWISE_DISTANCE_FUNCTIONS.get(
            metric, None
        ) is euclidean_distances:
            # zeroing diagonal, taking care of aliases of "euclidean",
            # i.e. "l2"
            D_chunk.flat[sl.start :: _num_samples(X) + 1] = 0
        if reduce_func is not None:
            chunk_size = D_chunk.shape[0]
            D_chunk = reduce_func(D_chunk, sl.start)
            _check_chunk_size(D_chunk, chunk_size)
        yield D_chunk


@validate_params(
    {
        "X": ["array-like", "sparse matrix"],
        "Y": ["array-like", "sparse matrix", None],
        "metric": [StrOptions(set(_VALID_METRICS) | {"precomputed"}), callable],
        "n_jobs": [Integral, None],
        "ensure_all_finite": ["boolean", StrOptions({"allow-nan"})],
    },
    prefer_skip_nested_validation=True,
)
def pairwise_distances(
    X,
    Y=None,
    metric="euclidean",
    *,
    n_jobs=None,
    ensure_all_finite=True,
    **kwds,
):
    """Compute the distance matrix from a feature array X and optional Y.

    This function takes one or two feature arrays or a distance matrix, and returns
    a distance matrix.

    - If `X` is a feature array, of shape (n_samples_X, n_features), and:

      - `Y` is `None` and `metric` is not 'precomputed', the pairwise distances
        between `X` and itself are returned.
      - `Y` is a feature array of shape (n_samples_Y, n_features), the pairwise
        distances between `X` and `Y` is returned.

    - If `X` is a distance matrix, of shape (n_samples_X, n_samples_X), `metric`