Skip to main content

module  pixeltable.functions

General Pixeltable UDFs. This parent module contains general-purpose UDFs that apply to multiple data types.

func  filter()

Signature
Keeps the elements of a JSON array for which a predicate holds, producing a new array. filter() is used like a UDF, for example in select() or add_computed_column(). Parameters:
  • expr (pixeltable.exprs.expr.Expr): The array to filter; an expression of type pxt.Json that resolves to a JSON array. Its element type is preserved in the result.
  • predicate (typing.Callable[[pixeltable.exprs.expr.Expr], typing.Any]): A Python function (typically a lambda) that decides which elements to keep. It receives x, a stand-in for a single array element, and returns a boolean condition; the element is kept when it is true. Operate on x exactly as you would on a column: comparisons, indexing (x[0]), field access (x.field), and JSON methods all work. Combine multiple conditions with & and |, and negate with ~ (not Python and/or/not). Example: lambda x: (x > 0) & (x < 10).
Returns:
  • pixeltable.exprs.expr.Expr: A new array containing the elements of expr for which predicate is true, unchanged. If expr is null or does not resolve to a JSON array, the result is null.
Examples: Given a table tbl with a pxt.Json column data holding lists of numbers, add a column that keeps only the positive numbers:
When data holds lists of objects such as {'score': 0.9, 'label': 'cat'}, keep only the high-confidence ones:

func  map()

Signature
Applies a function to each element of a JSON array, producing a new array. map() is used like a UDF, for example in select() or add_computed_column(). Parameters:
  • expr (pixeltable.exprs.expr.Expr): The array to map over; an expression of type pxt.Json that resolves to a JSON array. If its elements have a known type (e.g. the column is declared pxt.Json[[int]]), that type is available to fn and carries through to the result.
  • fn (typing.Callable[[pixeltable.exprs.expr.Expr], typing.Any]): A Python function (typically a lambda) applied to each element to produce its replacement. It receives x, a stand-in for a single array element, and returns the value to store in its place. Operate on x exactly as you would on a column: arithmetic, indexing (x[0]), field access (x.field), and JSON methods (x.len(), x.sum(), etc.) all work.
Returns:
  • pixeltable.exprs.expr.Expr: A new array holding fn(x) for each element x of expr. If expr is null or does not resolve to a JSON array, the result is null.
Examples: Given a table tbl with a pxt.Json column data holding lists of numbers, add a column that doubles each number:
When data holds lists of objects such as {'score': 0.9, 'label': 'cat'}, extract each score:

func  sort()

Signature
Sorts the elements of a JSON array, producing a new array. sort() is used like a UDF, for example in select() or add_computed_column(). Parameters:
  • expr (pixeltable.exprs.expr.Expr): The array to sort; an expression of type pxt.Json that resolves to a JSON array. Its element type is preserved in the result.
  • key (typing.Optional[typing.Callable[[pixeltable.exprs.expr.Expr], typing.Any]]): An optional Python function (typically a lambda) that produces the value each element is ordered by. It receives x, a stand-in for a single array element, and returns the sort key. Operate on x exactly as you would on a column: arithmetic, indexing (x[0]), field access (x.field), and JSON methods all work. When key is omitted, the elements are ordered by their own natural ordering.
  • asc (bool, default: True): Whether to sort in ascending (the default) or descending order.
Returns:
  • pixeltable.exprs.expr.Expr: A new array with the elements of expr in sorted order. If expr is null or does not resolve to a JSON array, the result is null. Sorting a list of scalars without a key, or by non-orderable keys, raises if the values are not mutually comparable (matching Python’s sorted()).
Examples: Given a table tbl with a pxt.Json column data holding lists of numbers, add a column that sorts each list in descending order:
When data holds lists of objects such as {'score': 0.9, 'label': 'cat'}, sort each list by score:

uda  count()

Signatures
Aggregate function that counts the number of non-null values in a column or grouping. Parameters:
  • val (String | None): The value to count.
Returns:
  • pxt.Int: The count of non-null values.
Examples: Count the number of non-null values in the value column of the table tbl:
Group by the category column and compute the count of non-null values in the value column for each category, assigning the name 'category_count' to the new column:

uda  max()

Signatures
Aggregate function that computes the maximum value in a column or grouping. Parameters:
  • val (String | None): The value to compare.
Returns:
  • pxt.String | None: The maximum value, or None if there are no non-null values.
Examples: Compute the maximum value in the value column of the table tbl:
Group by the category column and compute the maximum value in the value column for each category, assigning the name 'category_max' to the new column:

uda  mean()

Signatures
Aggregate function that computes the mean (average) of non-null values of a numeric column or grouping. Parameters:
  • val (Int | None): The numeric value to include in the mean.
Returns:
  • pxt.Float | None: The mean of the non-null values, or None if there are no non-null values.
Examples: Compute the mean of the values in the value column of the table tbl:
Group by the category column and compute the mean of the value column for each category, assigning the name 'category_mean' to the new column:

uda  min()

Signatures
Aggregate function that computes the minimum value in a column or grouping. Parameters:
  • val (String | None): The value to compare.
Returns:
  • pxt.String | None: The minimum value, or None if there are no non-null values.
Examples: Compute the minimum value in the value column of the table tbl:
Group by the category column and compute the minimum value in the value column for each category, assigning the name 'category_min' to the new column:

uda  sum()

Signatures
Aggregate function that computes the sum of non-null values of a numeric column or grouping. Parameters:
  • val (Int | None): The numeric value to add to the sum.
Returns:
  • pxt.Int | None: The sum of the non-null values, or None if there are no non-null values.
Examples: Sum the values in the value column of the table tbl:
Group by the category column and compute the sum of the value column for each category, assigning the name 'category_total' to the new column:
Last modified on July 20, 2026