#9576·dask

Documentation bug in dask.array.rot90

Author: JoachimoeCreated Oct 18, 2022Updated Sep 24, 2026
Labelsdocumentationneeds attention

As per https://docs.dask.org/en/stable/generated/dask.array.rot90.html, it states that dask.array.rot90 returns "a rotated view of m".

Looking at the source code, it is implemented as:

python
@derived_from(np)
def rot90(m, k=1, axes=(0, 1)):
    axes = tuple(axes)
    if len(axes) != 2:
        raise ValueError("len(axes) must be 2.")

    m = asanyarray(m)

    if axes[0] == axes[1] or np.absolute(axes[0] - axes[1]) == m.ndim:
        raise ValueError("Axes must be different.")

    if axes[0] >= m.ndim or axes[0] < -m.ndim or axes[1] >= m.ndim or axes[1] < -m.ndim:
        raise ValueError(f"Axes={axes} out of range for array of ndim={m.ndim}.")

    k %= 4

    if k == 0:
        return m[:]
    if k == 2:
        return flip(flip(m, axes[0]), axes[1])

    axes_list = list(range(0, m.ndim))
    (axes_list[axes[0]], axes_list[axes[1]]) = (axes_list[axes[1]], axes_list[axes[0]])

    if k == 1:
        return transpose(flip(m, axes[1]), axes_list)
    else:
        # k == 3
        return flip(transpose(m, axes_list), axes[1])

When looking at the return type of dask.array.flip it returns "The flipped array." I believe this is an error, because if flip returns the flipped version, then how does rot90 always return a view? I realize that if the if-clause triggers at $k == 1$, then transpose is called, which "returns a view of m with the entries of axis permuted. A view is returned whenever possible".

I believe the error stems from the fact that np.flip returns "A view of m with the entries of axis reversed. Since a view is returned, this operation is done in constant time." (https://numpy.org/doc/stable/reference/generated/numpy.flip.html)

So what does dask.rot90 return? If flip returns the flipped array, how is a view returned? Is this an error in the flip documentation?