GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add operator.is_none() · Issue #115808 · python/cpython

Add operator.is_none() #115808

New issue
Copy link
New issue
Copy link
Closed
#115814
Closed
Add operator.is_none()#115808
#115814
Copy link
Labels
type-featureA feature request or enhancementA feature request or enhancement

Description

@rhettinger
rhettinger
opened on Feb 22, 2024
Issue body actions

Feature or enhancement

Proposal:

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:

>>> from math import isnan
>>> from itertools import filterfalse
>>> data = [3.3, float('nan'), 1.1, 2.2]
>>> sorted(filterfalse(isnan, data))
[1.1, 2.2, 3.3]

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():

>>> data = ['c', None, 'a', 'b']
>>> sorted(filterfalse(is_none, data))
['a', 'b', 'c']

This helps fulfill a primary use case for the operator module which is to support functional programming with map(), filter(), etc.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

  • gh-115808: Add is_none and is_not_none operators #115814
Reacted by Alex Waygood, Arie Bovenberg, Erlend E. Aasland, Kirill Podoprigora and Gouvernathor

Activity

  1. rhettinger
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Feb 22, 2024
  2. ThexXTURBOXx
    added a commit that references this issue on Feb 22, 2024

    pythongh-115808: Add is_none operator

    63b788b
  3. rhettinger commented on Feb 22, 2024

    @rhettinger
    rhettinger
    on Feb 22, 2024
    ContributorAuthor
    More actions

    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
  4. AlexWaygood commented on Feb 22, 2024

    @AlexWaygood
    AlexWaygood
    on Feb 22, 2024
    Member
    More actions

    For convenience, it might also be nice to have is_not_none()

    Agreed -- I was going to suggest this. It also fits the general pattern of the operator module: we have both is_ and is_not, both truth and not_, etc.

    Reacted by Raymond Hettinger
  5. ThexXTURBOXx
    added a commit that references this issue on Mar 4, 2024

    pythongh-115808: Add is_none operator

    72ccb45
  6. AA-Turner
    added a commit that references this issue on Aug 10, 2024

    gh-115808: Add ``is_none`` and ``is_not_none`` to ``operator`` (#115814)

    5580f31
  7. AA-Turner
    closed this as completedin #115814on Aug 10, 2024
  8. blhsing
    added a commit that references this issue on Aug 22, 2024

    pythongh-115808: Add ``is_none`` and ``is_not_none`` to ``operator`` (p…

    34f25eb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.