It makes a lot of sense that this would fail, but
skimage.filter.rank.mean has a `mask` keyword argument that can do what you want. However, it only works for uint8 or uint16 images,
and if I remember correctly, it will be much slower if values exceed 12 bits, that is, your image intensity values should be in [0, 4096).
>>> from skimage.filter import rank
>>> arr = array([[np.nan, 1, 2, 3, 4, 5, np.nan]])
>>> selem = np.ones((3, 3))
>>> arr_mean1 = rank.mean(arr.astype(np.uint8), selem)
>>> arr_mean1
array([[0, 1, 2, 3, 4, 3, 2]], dtype=uint8)
>>> arr.astype(np.uint8)
array([[0, 1, 2, 3, 4, 5, 0]], dtype=uint8)
>>> nan_mask = True - np.isnan(arr)
>>> arr_mean2 = rank.mean(arr.astype(np.uint8), selem, mask=nan_mask)
>>> arr_mean2
array([[1, 1, 2, 3, 4, 4, 5]], dtype=uint8)
Juan.