Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Polars · Module

.is_null

Returns a boolean expression that identifies null values element by element. It can be applied to individual expressions or selected columns in DataFrame transformations.

How it works

Call is_null on an expression to produce a boolean expression that is true at positions containing a Polars null and false elsewhere. It operates element by element and can be applied to one column, all selected columns, or expressions inside transformations.

Syntax

Expr.is_null() → Expr

Returns

Expr; when evaluated, it produces a boolean Series indicating which values are null.

Key points

  • The evaluated result is boolean, with one indicator corresponding to each input value.
  • The method has no parameters and returns a Polars expression.
  • Apply it to all selected columns and append a suffix to the resulting indicator-column names.
  • A Python None in the example becomes a detected Polars null.
  • The documentation tests null detection alongside a floating-point NaN value.

Example: Mark null values

import polars as pl

df = pl.DataFrame({"a": [1, 2, None], "b": [None, 2.0, float("nan")]})
result = df.with_columns(
    pl.all().is_null().name.suffix("_isnull")
)
print(result)

Adds a boolean column for each input column, marking only Polars null values.

When to use it

Filter missing values

Create boolean masks for filtering rows whose selected fields are null.

Audit missingness

Add null-indicator columns during feature inspection or data-quality checks.

Check multiple columns

Apply the same null test to every selected column with a selector expression.

Interview questions

QWhat does Expr.is_null() return?

is_null() returns an expression whose evaluated result is a boolean Series indicating which values are null. It can be used in transformations such as with_columns and applied to multiple selected columns.

Follow-up: How would you distinguish null from NaN? is_null() detects null values, while the documented example demonstrates that NaN is reported separately rather than as null; use a NaN-specific check for floating-point NaN.

QWhat is the signature and element-wise behavior of Expr.is_null()?

The method takes no arguments and returns an Expr. When evaluated, each input value produces a boolean result: true for null and false for non-null values.

Follow-up: What happens when it is applied through pl.all()? Polars evaluates the expression for every selected column, producing corresponding boolean columns when used with with_columns.

QHow can is_null() be used across a DataFrame?

A common pattern is pl.all().is_null().name.suffix("_isnull") inside with_columns. This creates null-indicator columns while retaining the original data.

Follow-up: How can the generated columns be named? Use expression name manipulation such as name.suffix to append a suffix to each selected column name.

  • polars.Expr.is_not_null
  • polars.Expr.has_nulls
  • polars.Expr.name.suffix

Source: polars.Expr.is_null — Polars documentation. Checked 2026-10-15.