You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With floating point data, the float('NaN') special value is commonly used as a placeholder for missing values. We provide math.isnan to support stripping out those values prior to sorting or summation:
For non-float data, the None special value is commonly used as a placeholder for missing values. I propose a new function in the operator module analogous to math.isnan():
For convenience, it might also be nice to have is_not_none(). The matches what would be done in a typical list comprehension: cleaned = [x for x in data if x is not None]. Also, it would save the need to know about filterfalse() in itertools module which is less well known that builtin functions. A simple builtin filter() call will suffice: mean(filter(is_not_none, data)).
Reacted by Alex Waygood, Waket Zheng and Feuermurmel
Activity
pythongh-115808: Add is_none operator
rhettinger commentedon Feb 22, 2024
For convenience, it might also be nice to have
is_not_none(). The matches what would be done in a typical list comprehension:cleaned = [x for x in data if x is not None]. Also, it would save the need to know about filterfalse() in itertools module which is less well known that builtin functions. A simple builtin filter() call will suffice:mean(filter(is_not_none, data)).AlexWaygood commentedon Feb 22, 2024
Agreed -- I was going to suggest this. It also fits the general pattern of the
operatormodule: we have bothis_andis_not, bothtruthandnot_, etc.pythongh-115808: Add is_none operator
gh-115808: Add ``is_none`` and ``is_not_none`` to ``operator`` (#115814)
pythongh-115808: Add ``is_none`` and ``is_not_none`` to ``operator`` (p…