ext/polars/src/conversion.rs in polars-df-0.1.2 vs ext/polars/src/conversion.rs in polars-df-0.1.3
- old
+ new
@@ -1,6 +1,7 @@
-use magnus::{RArray, Symbol, TryConvert, Value, QNIL};
+use magnus::{class, RArray, Symbol, TryConvert, Value, QNIL};
+use polars::chunked_array::object::PolarsObjectSafe;
use polars::chunked_array::ops::{FillNullLimit, FillNullStrategy};
use polars::datatypes::AnyValue;
use polars::frame::DataFrame;
use polars::prelude::*;
use polars::series::ops::NullBehavior;
@@ -77,10 +78,17 @@
AnyValue::Float32(v) => Value::from(v),
AnyValue::Float64(v) => Value::from(v),
AnyValue::Null => *QNIL,
AnyValue::Boolean(v) => Value::from(v),
AnyValue::Utf8(v) => Value::from(v),
+ AnyValue::Date(v) => class::time()
+ .funcall::<_, _, Value>("at", (v * 86400,))
+ .unwrap()
+ .funcall::<_, _, Value>("utc", ())
+ .unwrap()
+ .funcall::<_, _, Value>("to_date", ())
+ .unwrap(),
_ => todo!(),
}
}
}
@@ -100,14 +108,23 @@
"i8" => DataType::Int8,
"i16" => DataType::Int16,
"i32" => DataType::Int32,
"i64" => DataType::Int64,
"str" => DataType::Utf8,
+ "bin" => DataType::Binary,
"bool" => DataType::Boolean,
+ "cat" => DataType::Categorical(None),
+ "date" => DataType::Date,
+ "datetime" => DataType::Datetime(TimeUnit::Microseconds, None),
"f32" => DataType::Float32,
+ "time" => DataType::Time,
+ "dur" => DataType::Duration(TimeUnit::Microseconds),
"f64" => DataType::Float64,
- "date" => DataType::Date,
+ // "obj" => DataType::Object(OBJECT_NAME),
+ "list" => DataType::List(Box::new(DataType::Boolean)),
+ "null" => DataType::Null,
+ "unk" => DataType::Unknown,
_ => {
return Err(RbValueError::new_err(format!(
"{} is not a supported DataType.",
ob
)))
@@ -404,6 +421,22 @@
e
)))
}
};
Ok(parsed)
+}
+
+pub struct ObjectValue {
+ pub inner: Value,
+}
+
+impl From<&dyn PolarsObjectSafe> for &ObjectValue {
+ fn from(val: &dyn PolarsObjectSafe) -> Self {
+ unsafe { &*(val as *const dyn PolarsObjectSafe as *const ObjectValue) }
+ }
+}
+
+impl ObjectValue {
+ pub fn to_object(&self) -> Value {
+ self.inner
+ }
}