This is to support `nanmean`, `nansum` (see #153), and `pad` (#461). The previous attempt at this in #468 was reverted in #469, since it was causing problems when used with Xarray (https://github.com/pydata/xarray/issues/8834#issuecomment-2124914727). When Xarray is working we can re-introduce the changes here.