def reorder_dims(darray, dim1, dim2):
    """Interchange two dimensions of a DataArray in a similar way as numpy's swap_axes

    Parameters
    ---------
    darray: Xarray.DataArray/TimeSeriesX
    dim1: str, the first dim we want to swap
    dim2: str, the second dim we want to swap

    Returns
    ---------
    transposed darray

    Example Usage
    -------------
    # Swap the timeseries object's first dim and time dim
    check_first_dim = timeseries.dims[0]
    timeseries_swapped_time_dim = reorder_dims(timeseries, dim1=check_first_dim, dim2='time')

    See
    -------
    https://github.com/pydata/xarray/issues/1081, rafa-guedes comment on Aug 21, 2017
    """
    dims = list(darray.dims)
    assert set([dim1, dim2]).issubset(dims
        ), 'dim1 and dim2 must be existing dimensions in darray'
    ind1, ind2 = dims.index(dim1), dims.index(dim2)
    dims[ind2], dims[ind1] = dims[ind1], dims[ind2]
    return darray.transpose(*dims)
