Function arrow_cast::cast::cast
source · pub fn cast(
array: &dyn Array,
to_type: &DataType
) -> Result<ArrayRef, ArrowError>
Expand description
Cast array
to the provided data type and return a new Array with
type to_type
, if possible.
Behavior:
- Boolean to Utf8:
true
=> ‘1’,false
=>0
- Utf8 to boolean:
true
,yes
,on
,1
=>true
,false
,no
,off
,0
=>false
, short variants are accepted, other strings return null or error - Utf8 to numeric: strings that can’t be parsed to numbers return null, float strings in integer casts return null
- Numeric to boolean: 0 returns
false
, any other value returnstrue
- List to List: the underlying data type is cast
- Primitive to List: a list array with 1 value per slot is created
- Date32 and Date64: precision lost when going to higher interval
- Time32 and Time64: precision lost when going to higher interval
- Timestamp and Date{32|64}: precision lost when going to higher interval
- Temporal to/from backing primitive: zero-copy with data type change
- Casting from
float32/float64
toDecimal(precision, scale)
rounds to thescale
decimals (i.e. casting 6.4999 to Decimal(10, 1) becomes 6.5). This is the breaking change from26.0.0
. It used to truncate it instead of round (i.e. outputs 6.4 instead)
Unsupported Casts
- To or from
StructArray
- List to primitive
- Interval and duration