Browse Source

add try from for floats

tags/v0.3.5
jacques Perrault 1 year ago
parent
commit
52045f3af8
1 changed files with 19 additions and 0 deletions
  1. +19
    -0
      libraries/arrow-convert/src/from_impls.rs

+ 19
- 0
libraries/arrow-convert/src/from_impls.rs View File

@@ -107,6 +107,25 @@ impl TryFrom<&ArrowData> for i64 {
}
}

impl TryFrom<&ArrowData> for f32 {
type Error = eyre::Report;
fn try_from(value: &ArrowData) -> Result<Self, Self::Error> {
let array = value
.as_primitive_opt::<arrow::datatypes::Float32Type>()
.context("not a primitive Float32Type array")?;
extract_single_primitive(array)
}
}
impl TryFrom<&ArrowData> for f64 {
type Error = eyre::Report;
fn try_from(value: &ArrowData) -> Result<Self, Self::Error> {
let array = value
.as_primitive_opt::<arrow::datatypes::Float64Type>()
.context("not a primitive Float64Type array")?;
extract_single_primitive(array)
}
}

impl<'a> TryFrom<&'a ArrowData> for &'a str {
type Error = eyre::Report;
fn try_from(value: &'a ArrowData) -> Result<Self, Self::Error> {


Loading…
Cancel
Save