Skip to content

Polars treats strings as large_strings automatically #1

@Schwarzam

Description

@Schwarzam

The code below is trying to apply the conversion before writing to the buffer to respond. It does not apply any dtype change to the column.
I tryed multiple ways but the lack of documentation and access to low level in polars limits this possibility of conversion.

use polars::prelude::*;
// Converting from LargeUtf8 to Utf8
let col_names = df.get_column_names_owned();
for (index, name) in col_names.iter().enumerate() {
    
    let col = df.column(&name).unwrap();
    if col.dtype() == &ArrowDataType::LargeUtf8 {
        let new_col = &col.strict_cast(&DataType::from_arrow(&ArrowDataType::Utf8, true))?;
        //let new_col = col.u8().unwrap();
        df.replace_column(index, new_col.to_owned().into_series()).unwrap();
    }
}

// Checking if anything changed
for (index, name) in col_names.iter().enumerate() {
    let col = df.column(&name).unwrap();
    if col.dtype() == &ArrowDataType::LargeUtf8 {
        println!("Column in LargeUtf8 {:?}", name);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions