Np.delete unexpected behaviour in an njit funcion

Hello!
Amazing job with the numba version 0.52.0, I would like to report what seems to be an unexpected behaviour (in my limited experience)

a = np.asarray([[1,2,-3,-3,4],[0,0,0,0,0]])
#This works without njiting
@njit
def fii(arr, val):
    return np.delete(arr, np.where(arr==val))
fii(a, -3)

The point is that with arr (input arr) is a 1D array; njited fii() only works if np.where does not return the tuple ([whatever indexes],)

'''this works:'''
a = np.asarray([1,2,-3,-3,4])
#Does not work if you don't delete the tuple returned by np.where
@njit
def fii(arr, val):
    return np.delete(arr, np.where(arr==val)[0])
fii(a, -3)

If using numpy, it works correctly in all the cases, is this something expected?

Thanks a lot and congrats on your amazing job!

Hi and thank you for your kind words. We do appreciate your feedback! Could you perhaps elaborate on the results you expect and what you see instead. I.e. what does “does not work” mean?

Hi Esc, and thanks! I would like these two njitted function to work:

a = np.asarray([[1,2,-3,-3,4],[0,0,0,0,0]])
#This works without njiting
@njit
def fii(arr, val):
    return np.delete(arr, np.where(arr==val))

b = np.asarray([1,2,-3,-3,4])
@njit
def fee(arr, val):
    return np.delete(arr, np.where(arr==val))# [0]

fii(a,-3)
fee(b, -3)

Hi @jaistech-sp,

I think Numba is implementing the specification:
https://numpy.org/doc/stable/reference/generated/numpy.delete.html
where the second argument, obj, is described as:

obj slice, int or array of ints

and in the case presented np.where is returning a tuple or np.ndarray. I think NumPy is dealing with this by doing asarray followed by ravel:

I suggest opening a feature request on Numba’s issue tracker if this is important to you. It could well require clarification from NumPy before a fix is made. As a work around, can you just do the indexing for now?

Hope this helps?

Hi Stuart,
Thanks a lot for the replay, somehow I figure it out like raveling the array and reshaping. Please let me know if it worth for Numba to have an open issue on that topic and I will do so.

@jaistech-sp no problem. You are most welcome to open an issue if it’s important to you. Thanks.