Skip to main content

module  pixeltable.functions

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

func  map()

Signature
map(
    expr: pixeltable.exprs.expr.Expr,
    fn: Callable[[pixeltable.exprs.expr.Expr], Any]
) -> pixeltable.exprs.expr.Expr
Applies a mapping function to each element of a list. Parameters:
  • expr (pixeltable.exprs.expr.Expr): The list expression to map over; must be an expression of type pxt.Json.
  • fn (typing.Callable[[pixeltable.exprs.expr.Expr], typing.Any]): An operation on Pixeltable expressions that will be applied to each element of the JSON array.
Examples: Given a table tbl with a column data of type pxt.Json containing lists of integers, add a computed column that produces new lists with each integer doubled:
tbl.add_computed_column(
    doubled=pxt.functions.map(t.data, lambda x: x * 2)
)

uda  count()

Signatures
# Signature 1:
@pxt.uda
count(val: pxt.String | None) -> pxt.Int

# Signature 2:
@pxt.uda
count(val: pxt.Bool | None) -> pxt.Int

# Signature 3:
@pxt.uda
count(val: pxt.Int | None) -> pxt.Int

# Signature 4:
@pxt.uda
count(val: pxt.Float | None) -> pxt.Int

# Signature 5:
@pxt.uda
count(val: pxt.Timestamp | None) -> pxt.Int

# Signature 6:
@pxt.uda
count(val: pxt.Date | None) -> pxt.Int

# Signature 7:
@pxt.uda
count(val: pxt.UUID | None) -> pxt.Int

# Signature 8:
@pxt.uda
count(val: pxt.Json | None) -> pxt.Int

# Signature 9:
@pxt.uda
count(val: pxt.Array | None) -> pxt.Int

# Signature 10:
@pxt.uda
count(val: pxt.Image | None) -> pxt.Int

# Signature 11:
@pxt.uda
count(val: pxt.Video | None) -> pxt.Int

# Signature 12:
@pxt.uda
count(val: pxt.Audio | None) -> pxt.Int

# Signature 13:
@pxt.uda
count(val: pxt.Document | None) -> pxt.Int
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:
tbl.select(pxt.functions.count(tbl.value)).collect()
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:
tbl.group_by(tbl.category).select(
    tbl.category, category_count=pxt.functions.count(tbl.value)
).collect()

uda  max()

Signatures
# Signature 1:
@pxt.uda
max(val: pxt.String | None) -> pxt.String | None

# Signature 2:
@pxt.uda
max(val: pxt.Int | None) -> pxt.Int | None

# Signature 3:
@pxt.uda
max(val: pxt.Float | None) -> pxt.Float | None

# Signature 4:
@pxt.uda
max(val: pxt.Bool | None) -> pxt.Bool | None

# Signature 5:
@pxt.uda
max(val: pxt.Timestamp | None) -> pxt.Timestamp | None
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:
tbl.select(pxt.functions.max(tbl.value)).collect()
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:
tbl.group_by(tbl.category).select(
    tbl.category, category_max=pxt.functions.max(tbl.value)
).collect()

uda  mean()

Signatures
# Signature 1:
@pxt.uda
mean(val: pxt.Int | None) -> pxt.Float | None

# Signature 2:
@pxt.uda
mean(val: pxt.Float | None) -> pxt.Float | None
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:
tbl.select(pxt.functions.mean(tbl.value)).collect()
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:
tbl.group_by(tbl.category).select(
    tbl.category, category_mean=pxt.functions.mean(tbl.value)
).collect()

uda  min()

Signatures
# Signature 1:
@pxt.uda
min(val: pxt.String | None) -> pxt.String | None

# Signature 2:
@pxt.uda
min(val: pxt.Int | None) -> pxt.Int | None

# Signature 3:
@pxt.uda
min(val: pxt.Float | None) -> pxt.Float | None

# Signature 4:
@pxt.uda
min(val: pxt.Bool | None) -> pxt.Bool | None

# Signature 5:
@pxt.uda
min(val: pxt.Timestamp | None) -> pxt.Timestamp | None
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:
tbl.select(pxt.functions.min(tbl.value)).collect()
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:
tbl.group_by(tbl.category).select(
    tbl.category, category_min=pxt.functions.min(tbl.value)
).collect()

uda  sum()

Signatures
# Signature 1:
@pxt.uda
sum(val: pxt.Int | None) -> pxt.Int | None

# Signature 2:
@pxt.uda
sum(val: pxt.Float | None) -> pxt.Float | None
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:
tbl.select(pxt.functions.sum(tbl.value)).collect()
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:
tbl.group_by(tbl.category).select(
    tbl.category, category_total=pxt.functions.sum(tbl.value)
).collect()