No conversion from none to array(float64, 1d, A) for '$82return_value.1', defined at None

I tried to defined a shift function like this:

@njit(float64[:](float64[:], int64))
def shift_arr(arr, shift):
    """ arr : e.g. np.array([9, 8, 7, 6, 5])
        shift : e.g. 2 or -2, positive means right shift, negative means left shift
        right shift by 2 will return array([0, 0, 9, 8, 7])
        left shift by 2 will return array([7, 6, 5, 0, 0])
    """
    if shift > 0:
        return np.concatenate((np.zeros(shift), arr[:-shift]))
    elif shift < 0:
        return np.concatenate((arr[-shift:], np.zeros(-shift)))

The above code raised a

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No conversion from none to array(float64, 1d, A) for '$82return_value.1', defined at None

Could anyone please help with this? Many thanks.

This will work, as all the branch cases are covered:

@njit(float64[:](float64[:], int64))
def shift_arr(arr, shift):
    """ arr : e.g. np.array([9, 8, 7, 6, 5])
        shift : e.g. 2 or -2, positive means right shift, negative means left shift
        right shift by 2 will return array([0, 0, 9, 8, 7])
        left shift by 2 will return array([7, 6, 5, 0, 0])
    """
    if shift > 0:
        return np.concatenate((np.zeros(shift), arr[:-shift]))
    return np.concatenate((arr[-shift:], np.zeros(-shift)))
1 Like

Indeed. Thanks a lot.