Skip to main content

Module past_calendar

Module past_calendar 

Source
Expand description

Polars operations that panic on a date or datetime past the calendar’s range (a sentinel like i64::MIN + 1 microseconds): a cast to text, dt.to_string, and the date parts that go through a calendar date (dt.date with a zone, dt.month_start, dt.truncate, …). Each panics for the whole column, even when one row holds such a value.

datui cannot patch Polars, so it gives these operations the values they can take: text is Polars’ own, with a value past the calendar written as its stored number (crate::exact::out_of_range), as the table shows it; a date part of such a value is null, as Polars’ own dt.year makes it. Everything here is elementwise, so a streamed plan stays streamed, and costs a min and a max per batch when no value is past the calendar.

A nanosecond datetime is always in the calendar, but date math near the ends of its range (1677-09-21, 2262-04-11) overflows in Polars: a value it could move past them is null too (ns_within_reach).

Functions§

calendar_expr
expr with each date or datetime past the calendar as null, ahead of a date part that would panic on it. Any other value, and any other type, as it is.
can_leave_calendar
Whether a value of dtype can lie past the calendar: a date, or a datetime in milliseconds or microseconds. A count of nanoseconds only spans 1677..2262.
cast_text
series cast to String as Polars casts it, with a date or datetime past the calendar as its stored number.
format_expr
formatted in a plan: expr.dt().to_string(format) that never panics.
formatted
Polars’ dt.to_string(format), with a date or datetime past the calendar as its stored number.
guard_expr
expr with every operation that would panic on a date past the calendar replaced by one that does not: casts to text and concat_str go through text_expr, dt.to_string through format_expr, and the date parts read from calendar_expr. With schema, the one expr is evaluated against, only operations on a date or ms/us datetime are replaced and every other plan stays as Polars built it; without it, each is replaced, and the replacement casts any other type as Polars would. A date that meets text in a coalesce or a when/then/otherwise, which Polars casts to text itself, goes through text_expr too, but only with schema, which says the result is text. Date math that overflows near the ends of the nanosecond range reads from ns_edge_expr. A date cast to a datetime, or met with one in a coalesce, a when/then/otherwise, fill_null or a horizontal min or max (the last ones only with schema), goes through countable_expr.
guard_plan
guard_expr over each expression of plan, against the schema of the input it is evaluated on: a SQL statement’s plan, whose casts and date functions are Polars’ own. Only the parts of the plan holding such an expression are rebuilt.
text_expr
cast_text in a plan: expr.cast(String) that never panics.
text_or_stored
A date or datetime column as text writes it, with a value past the calendar, on which text would panic, written as its stored number instead.