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));

ModulesΒ§

binary πŸ”’
Cast support for binary, fixed-size binary and byte-view arrays.
decimal πŸ”’
dictionary πŸ”’
list πŸ”’
map πŸ”’
run_array πŸ”’
string πŸ”’
structs πŸ”’
temporal πŸ”’
Cast support for temporal arrays: timestamps, dates, durations, intervals, and timezones.
union πŸ”’
Cast support for union arrays.

MacrosΒ§

numeric_native πŸ”’

StructsΒ§

CastOptions
CastOptions provides a way to override the default cast behaviors
NumericKind πŸ”’
Properties of a numeric native type that decide whether num_cast to another numeric type can fail.

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.

TraitsΒ§

DecimalCast
A utility trait that provides checked conversions between decimal types inspired by NumCast
NumericNative πŸ”’
A native type with a NumericKind.

FunctionsΒ§

bool_to_numeric_cast πŸ”’
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_bool_to_numeric πŸ”’
Cast Boolean types to numeric
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_from_decimal πŸ”’
cast_integer_to_decimal πŸ”’
cast_num_to_bool
Cast numeric types to boolean
cast_numeric_arrays πŸ”’
Convert Array into a PrimitiveArray of type, and apply numeric cast
cast_numeric_to_bool πŸ”’
Cast numeric types to Boolean
cast_reinterpret_arrays πŸ”’
Cast the primitive array using [PrimitiveArray::reinterpret_cast]
cast_single_string_to_boolean_default
Cast a single string to boolean with default cast option(safe=true).
cast_time64_to_time32 πŸ”’
cast_to_decimal πŸ”’
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.
integer_to_decimal_native πŸ”’
Convert an integer to a decimal native value without wrapping.
integers_fit_digits πŸ”’
Returns true if every value of array has at most digits decimal digits.
is_infallible_numeric_cast πŸ”’
Returns true if num_cast succeeds for every value of from when casting to to: every cast to a float, and integer casts whose target holds every source value.
num_cast
Natural cast between numeric types Return None if the input value can’t be casted to type O.
parse_string_to_decimal_nativeDeprecated
Parses the given string as a decimal with the given scale, returning the unscaled representation in the decimal type’s native integer (e.g. i32 for Decimal32Type, i256 for Decimal256Type).
rescale_decimal
Rescales a decimal value from (input_precision, input_scale) to (output_precision, output_scale) and returns the converted number when it fits within the output precision.
single_bool_to_numeric
Cast single bool value to numeric value.
single_decimal_to_float_lossy
Lossy conversion from decimal to float.
single_float_to_decimal
Cast a single floating point value to a decimal native with the given multiple. Returns None if the value cannot be represented with the requested precision.
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