human
Complete this python program:
def _box_size(points, width=None, height=None, padding=0.0):
assistant
#Here is the Python code you requested.

    """Given a series of points, calculate an appropriate box size.
    Parameters
    points : array, shape (n_points, 2)
    The centers of the axes as a list of (x, y) coordinate pairs. Normally
    these are points in the range [0, 1] centered at 0.5.
    width : float | None
    An optional box width to enforce. When set, only the box height will be
    calculated by the function.
    height : float | None
    An optional box height to enforce. When set, only the box width will be
    calculated by the function.
    padding : float
    Portion of the box to reserve for padding. The value can range between
    0.0 (boxes will touch, default) to 1.0 (boxes consist of only padding).
    Returns
    width : float
    Width of the box
    height : float
    Height of the box
    """
    from scipy.spatial.distance import pdist
    def xdiff(a, b):
        return np.abs((a[0] - b[0]))
    def ydiff(a, b):
        return np.abs((a[1] - b[1]))
    points = np.asarray(points)
    all_combinations = list(combinations(points, 2))
    if ((width is None) and (height is None)):
        if (len(points) <= 1):
            width = 1.0
            height = 1.0
        else:
            (a, b) = all_combinations[np.argmin(pdist(points))]
            (w, h) = (xdiff(a, b), ydiff(a, b))
            if (w > h):
                width = w
            else:
                height = h
    if (height is None):
        hdist = pdist(points, xdiff)
        candidates = [all_combinations[i] for (i, d) in enumerate(hdist) if (d < width)]
        if (len(candidates) == 0):
            height = 1.0
        else:
            height = np.min([ydiff(*c) for c in candidates])
    elif (width is None):
        vdist = pdist(points, ydiff)
        candidates = [all_combinations[i] for (i, d) in enumerate(vdist) if (d < height)]
        if (len(candidates) == 0):
            width = 1.0
        else:
            width = np.min([xdiff(*c) for c in candidates])
    width *= (1 - padding)
    height *= (1 - padding)
    return (width, height)