import math


def get_grid_size(cell_count):
    """
    Determines the best grid shape for a given cell count.
    The best grid shape is the one closest to square that minimises the number
    of blank cells.
    e.g. for a square number, it is the corresponding square root.
    >>> get_grid_size(25)
    (5, 5)
    It will otherwise be a rectangle, with the one value matching the
    square root
    >>> get_grid_size(20)
    (5, 4)
    If the number does not fit perfectly into such a rectangle, then it will
    be a rectangle the next size up.
    >>> get_grid_size(15)
    (4, 4)
    """
    sqrt = math.sqrt(cell_count)
    sqrt_floor = int(math.floor(sqrt))
    if sqrt == sqrt_floor:
        # perfect square
        cols = sqrt_floor
        rows = sqrt_floor
    else:
        # Otherwise, this is a rectangle.
        # Expand cols to accommodate
        cols = sqrt_floor + 1
        # Expand rows if needed
        rows = sqrt_floor + (1 if cell_count > sqrt_floor * cols else 0)

    # PIL image sizes are width x height - analogous with cols x rows
    return cols, rows