Sha256: 79775c577aa4a533ed474c9c062e0b87d5c8e34cc7b47033190059b5aab3686b

Contents?: true

Size: 1.09 KB

Versions: 7

Compression:

Stored size: 1.09 KB

Contents

use magnus::{RHash, Value};

use crate::conversion::Wrap;
use crate::file::get_file_like;
use crate::prelude::DataType;
use crate::{RbPolarsErr, RbResult};

pub fn read_ipc_schema(rb_f: Value) -> RbResult<RHash> {
    use polars_core::export::arrow::io::ipc::read::read_file_metadata;
    let mut r = get_file_like(rb_f, false)?;
    let metadata = read_file_metadata(&mut r).map_err(RbPolarsErr::from)?;

    let dict = RHash::new();
    for field in &metadata.schema.fields {
        let dt: Wrap<DataType> = Wrap((&field.data_type).into());
        dict.aset(field.name.clone(), dt)?;
    }
    Ok(dict)
}

pub fn read_parquet_schema(rb_f: Value) -> RbResult<RHash> {
    use polars_parquet::read::{infer_schema, read_metadata};

    let mut r = get_file_like(rb_f, false)?;
    let metadata = read_metadata(&mut r).map_err(RbPolarsErr::from)?;
    let arrow_schema = infer_schema(&metadata).map_err(RbPolarsErr::from)?;

    let dict = RHash::new();
    for field in arrow_schema.fields {
        let dt: Wrap<DataType> = Wrap((&field.data_type).into());
        dict.aset(field.name, dt)?;
    }
    Ok(dict)
}

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
polars-df-0.13.0 ext/polars/src/functions/io.rs
polars-df-0.12.0 ext/polars/src/functions/io.rs
polars-df-0.11.0 ext/polars/src/functions/io.rs
polars-df-0.10.0 ext/polars/src/functions/io.rs
polars-df-0.9.0 ext/polars/src/functions/io.rs
polars-df-0.8.0 ext/polars/src/functions/io.rs
polars-df-0.7.0 ext/polars/src/functions/io.rs