We had this discussion about a year and a half ago, in which I strongly advocated exactly this keyword argument to median*().

As before, I don't care about the default if there is an option.  I don't even really care about the exception case, but don't object to it.

On Mon, Aug 23, 2021 at 11:55 PM Steven D'Aprano <steve@pearwood.info> wrote:
At the moment, the handling of NANs in the statistics module is
implementation dependent. In practice, that *usually* means that if your
data has a NAN in it, the result you get will probably be a NAN.

    >>> statistics.mean([1, 2, float('nan'), 4])
    nan

But there are unfortunate exceptions to this:

    >>> statistics.median([1, 2, float('nan'), 4])
    nan
    >>> statistics.median([float('nan'), 1, 2, 4])
    1.5

I've spoken to users of other statistics packages and languages, such as
R, and I cannot find any consensus on what the "right" behaviour should
be for NANs except "not that!".

So I propose that statistics functions gain a keyword only parameter to
specify the desired behaviour when a NAN is found:

- raise an exception

- return NAN

- ignore it (filter out NANs)

which seem to be the three most common preference. (It seems to be
split roughly equally between the three.)

Thoughts? Objections?

Does anyone have any strong feelings about what should be the default?


--
Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/EDRF2NR4UOYMSKE64KDI2SWUMKPAJ3YM/
Code of Conduct: http://python.org/psf/codeofconduct/


--
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.