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Β§
- Cast
Options - CastOptions provides a way to override the default cast behaviors
- Numeric
Kind π - Properties of a numeric native type that decide whether
num_castto another numeric type can fail.
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.
TraitsΒ§
- Decimal
Cast - A utility trait that provides checked conversions between
decimal types inspired by
NumCast - Numeric
Native π - A native type with a
NumericKind.
FunctionsΒ§
- bool_
to_ πnumeric_ cast - 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_
bool_ πto_ numeric - Cast Boolean types to numeric
- 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_
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
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.
- integer_
to_ πdecimal_ native - Convert an integer to a decimal native value without wrapping.
- integers_
fit_ πdigits - Returns true if every value of
arrayhas at mostdigitsdecimal digits. - is_
infallible_ πnumeric_ cast - Returns true if
num_castsucceeds for every value offromwhen casting toto: 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
valuecanβt be casted to typeO. - parse_
string_ to_ decimal_ native Deprecated - Parses the given string as a decimal with the given scale, returning the
unscaled representation in the decimal typeβs native integer (e.g.
i32forDecimal32Type,i256forDecimal256Type). - 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
Noneif 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
Tunits in one day