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 exprwith 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
dtypecan lie past the calendar: a date, or a datetime in milliseconds or microseconds. A count of nanoseconds only spans 1677..2262. - cast_
text seriescast to String as Polars casts it, with a date or datetime past the calendar as its stored number.- format_
expr formattedin 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 exprwith every operation that would panic on a date past the calendar replaced by one that does not: casts to text andconcat_strgo throughtext_expr,dt.to_stringthroughformat_expr, and the date parts read fromcalendar_expr. Withschema, the oneexpris 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 throughtext_exprtoo, but only withschema, which says the result is text. Date math that overflows near the ends of the nanosecond range reads fromns_edge_expr. A date cast to a datetime, or met with one in a coalesce, a when/then/otherwise,fill_nullor a horizontal min or max (the last ones only withschema), goes throughcountable_expr.- guard_
plan guard_exprover each expression ofplan, 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_textin a plan:expr.cast(String)that never panics.- text_
or_ stored - A date or datetime column as
textwrites it, with a value past the calendar, on whichtextwould panic, written as its stored number instead.