I think the logical choice would be to allow a weighted average in the 
nan-functions, not to change `np.average`. In particular, I think it is bad API 
to add options for such exclusions; we have another open issue about infinitiy 
in the data, which leads to nan even with weight 0 (because `0*inf = nan`; see 
https://github.com/numpy/numpy/issues/25362); should that gets its own option?

It also seems a case that is *very* easily solved by the user with a wrapper, 
or, as noted in the issue, with creating a mask and using `np.ma.average`. Or, 
indeed, just calculating `np.nansum(data * weight, axis=...) / 
np.nansum(weight, axis=...)`

Anyway, my 2ยข would be to think whether we actually need this addition, and, if 
we decide we do, to see how this would fit with the `nan*` functions. This 
might mean introducing `np.nanaverage` since the Array API is fairly clear that 
`mean()` should be unweighted. Indeed, if written such that the `NaN` skipping 
is done after data and weight are multiplied, that would solve 
https://github.com/numpy/numpy/issues/25362 too.

-- Marten

p.s. My other reason for hesitation is that generally when you get a NaN, 
something is actually wrong...

> I would love some input on this issue, 
> https://github.com/numpy/numpy/issues/21375.
>
> I have created a draft PR which I believe resolves it, 
> https://github.com/numpy/numpy/pull/25474. Decided to go with adding 
> ignore_nan to np.average rather than adding weights to np.nanmean as it 
> seemed logical and was the path of least resistance.
> Please let me know what you think!
> -awestm
_______________________________________________
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com

Reply via email to