Expand description
Cast kernels to convert [ArrayRef] between supported datatypes.
See cast_with_options for more information on specific conversions.
Example:
// int32 to float64
let a = Int32Array::from(vec![5, 6, 7]);
let b = cast(&a, &DataType::Float64).unwrap();
let c = b.as_primitive::<Float64Type>();
assert_eq!(5.0, c.value(0));
assert_eq!(6.0, c.value(1));
assert_eq!(7.0, c.value(2));Re-exportsΒ§
pub(crate) use crate::cast::numeric::cast_bool_to_numeric;πpub(crate) use crate::cast::numeric::cast_numeric_arrays;πpub(crate) use crate::cast::numeric::cast_numeric_to_bool;πpub use crate::cast::numeric::cast_num_to_bool;pub use crate::cast::numeric::num_cast;pub use crate::cast::numeric::single_bool_to_numeric;use chrono::TimeZone;πuse chrono::Utc;πuse std::cmp::Ordering;πuse std::sync::Arc;πuse crate::display::ArrayFormatter;πuse crate::display::FormatOptions;πuse crate::parse::Parser;πuse crate::parse::parse_interval_day_time;πuse crate::parse::parse_interval_month_day_nano;πuse crate::parse::parse_interval_year_month;πuse crate::parse::string_to_datetime;πuse arrow_array::timezone::Tz;πuse arrow_buffer::ArrowNativeType;πuse arrow_buffer::OffsetBuffer;πuse arrow_buffer::i256;πuse arrow_data::ArrayData;πuse arrow_data::transform::MutableArrayData;πuse arrow_select::take::take;πuse num_traits::NumCast;πuse num_traits::ToPrimitive;πuse num_traits::cast::AsPrimitive;πpub use decimal::DecimalCast;pub use decimal::float_to_decimal;pub use decimal::float_to_decimal_opt;pub use decimal::rescale_decimal;pub use decimal::parse_string_to_decimal_native;Deprecated pub use decimal::single_float_to_decimal;Deprecated pub use string::cast_single_string_to_boolean_default;use crate::cast::binary::*;πuse crate::cast::decimal::*;πuse crate::cast::dictionary::*;πuse crate::cast::list::*;πuse crate::cast::map::*;πuse crate::cast::run_array::*;πuse crate::cast::string::*;πuse crate::cast::structs::*;πuse crate::cast::temporal::*;πuse arrow_array::builder::*;πuse arrow_array::cast::*;πuse arrow_array::temporal_conversions::*;πuse arrow_array::types::*;πuse arrow_array::*;πuse arrow_schema::*;π
ModulesΒ§
- binary π
- Cast support for binary, fixed-size binary and byte-view arrays.
- decimal π
- dictionary π
- list π
- map π
- numeric π
- Cast support for numeric and boolean arrays.
- run_
array π - string π
- structs π
- temporal π
- Cast support for temporal arrays: timestamps, dates, durations, intervals, and timezones.
- union π
- Cast support for union arrays.
StructsΒ§
- Cast
Options - CastOptions provides a way to override the default cast behaviors
ConstantsΒ§
- F32_
EXACT_ πINT_ LIMIT - Integers below 2^24 convert to an
f32exactly. - F64_
EXACT_ πINT_ LIMIT - Integers below 2^53 convert to an
f64exactly.
FunctionsΒ§
- can_
cast_ types - Return true if a value of type
from_typecan be cast into a value ofto_type. - cast
- Cast
arrayto the provided data type and return a new Array with typeto_type, if possible. - cast_
decimal_ πto_ f32 - Casts a decimal array to
Float32, rounding each value once. Same shape ascast_decimal_to_f64, with the smaller bounds anf32allows: integers are exact below 2^24, and10^konly up tok = 10. - cast_
decimal_ πto_ f64 - Casts a decimal array to
Float64, rounding each value once. - cast_
reinterpret_ πarrays - Cast the primitive array using [
PrimitiveArray::reinterpret_cast] - cast_
time64_ πto_ time32 - cast_
with_ options - Try to cast
arraytoto_typeif possible. - decimal_
to_ πf32_ rounded_ once - As
decimal_to_f64_rounded_once, but narrowing tof32in one step. Rounding tof64first and then tof32rounds twice: a decimal just above anf32midpoint can collapse onto that midpoint inf64, and round-half-even then sends it the wrong way. - decimal_
to_ πf64_ rounded_ once - Rounds once for the values the arithmetic cannot convert exactly, by parsing the decimalβs own text.
- resolve_
child_ array - Selects the best-matching child array from a [
UnionArray] for a given target type - same_
type_ family - single_
decimal_ to_ float_ lossy - Lossy conversion from decimal to float.
- time_
unit_ πmultiple - Get the time unit as a multiple of a second
- union_
extract_ by_ type - Extracts the best-matching child array from a [
UnionArray] for a given target type, and casts it to that type. - units_
per_ πday - Number of
Tunits in one day