Group by a truncated datetime

Group the input rows based on the specified column expression truncated to the specified granularity. This is similar to the DATE_TRUNC function in SQL.

ArgumentRemarks
date_truncThe date or time period to truncate the input datetime to.
argThe input expression — only an Index Column expression is accepted.

group_key.$OFFSET if this is the N-th expression in the group_by clause.

See also: Select the group key columns

import vitalx.aggregation as va

# Truncate to every 1 day.
va.select(...).group_by(
    va.date_trunc(va.Sleep.index(), 1, "day"),
)

# Truncate to every 3 months.
va.select(...).group_by(
    va.date_trunc(va.Sleep.index(), 3, "month"),
)

Group by a date or time component

Group the input rows based on a specific date or time component extracted from the specified column expression. This is similar to the DATE_PART function in SQL.

ArgumentRemarks
date_partThe date or time unit to extract.
argThe input expression — only an Index Column expression is accepted.

group_key.$OFFSET if this is the N-th expression in the group_by clause.

See also: Select the group key columns

import vitalx.aggregation as va

# Extract the weekday
va.select(...).group_by(
    va.date_part(va.Sleep.index(), "weekday"),
)

# Extract the day-of-month
va.select(...).group_by(
    va.date_part(va.Sleep.index(), "day")
)