Skip to main content

Module cast

Module cast 

Source
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Β§

CastOptions
CastOptions provides a way to override the default cast behaviors

ConstantsΒ§

F32_EXACT_INT_LIMIT πŸ”’
Integers below 2^24 convert to an f32 exactly.
F64_EXACT_INT_LIMIT πŸ”’
Integers below 2^53 convert to an f64 exactly.

FunctionsΒ§

can_cast_types
Return true if a value of type from_type can be cast into a value of to_type.
cast
Cast array to the provided data type and return a new Array with type to_type, if possible.
cast_decimal_to_f32 πŸ”’
Casts a decimal array to Float32, rounding each value once. Same shape as cast_decimal_to_f64, with the smaller bounds an f32 allows: integers are exact below 2^24, and 10^k only up to k = 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 array to to_type if possible.
decimal_to_f32_rounded_once πŸ”’
As decimal_to_f64_rounded_once, but narrowing to f32 in one step. Rounding to f64 first and then to f32 rounds twice: a decimal just above an f32 midpoint can collapse onto that midpoint in f64, 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 T units in one day