None versus MISSING sentinel -- request for design feedback

Steven D'Aprano steve+comp.lang.python at
Fri Jul 15 06:19:38 EDT 2011

Rob Williscroft wrote:

> Steven D'Aprano wrote in news:4e1fd009$0$29986$c3e8da3
> $5496439d at in gmane.comp.python.general:
>> I'm designing an API for some lightweight calculator-like statistics
>> functions, such as mean, standard deviation, etc., and I want to support
>> missing values. Missing values should be just ignored. E.g.:
>> mean([1, 2, MISSING, 3]) => 6/3 = 2 rather than 6/4 or raising an error.
> If you can't make your mind up then maybe you shouldn't:

Heh, good point.

It's not so much that I can't make up my mind -- I have a preferred solution
in mind, but I want to hear what sort of interface for dealing with missing
values others expect, and I don't want to prejudice others too greatly.

> MISSING = MissingObject()
> def mean( sequence, missing = MISSING ):

So you think the right API is to allow the caller to specify what counts as
a missing value at runtime? Are you aware of any other statistics packages
that do that?


More information about the Python-list mailing list