Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

experimenting with self-own branch #87

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust/polars-ocaml/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ crate-type = ["staticlib", "cdylib"]
[dependencies]
chrono = "0.4.26"
ocaml = "0.22.4"
ocaml-interop = "0.9.2"
ocaml-interop = {git = "https://github.com/tiny-book2/ocaml-interop", rev = "b53ea2ec4792e98a1ac8a6496396ad3eb4501ab0"}
ocaml-sys = "0.23.0"
polars-sql = "0.32.1"
smartstring = "1.0.1"
Expand Down
8 changes: 4 additions & 4 deletions rust/polars-ocaml/src/data_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,16 @@ fn rust_data_frame_columns(
let Abstract(data_frame) = data_frame.to_rust(cr);
let names: Vec<String> = names.to_rust(cr);
let data_frame = data_frame.borrow();
data_frame
(data_frame
.columns(&names)
.map(|series| {
series
.into_iter()
.map(|series| Abstract(Rc::new(RefCell::new(series.clone()))))
.collect::<Vec<Abstract<_>>>()
})
.map_err(|err| err.to_string())
.to_ocaml(cr)
.map_err(|err| err.to_string()))
.to_ocaml(cr)
}

#[ocaml_interop_export]
Expand All @@ -285,7 +285,7 @@ fn rust_data_frame_get_column_names(
) -> OCaml<OCamlList<String>> {
let Abstract(data_frame) = data_frame.to_rust(cr);
let data_frame = data_frame.borrow();
data_frame.get_column_names().to_ocaml(cr)
(&data_frame.get_column_names()).to_ocaml(cr)
}

#[ocaml_interop_export]
Expand Down
41 changes: 19 additions & 22 deletions rust/polars-ocaml/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ where
T: Clone + 'static,
R: 'static,
E: std::string::ToString,
Result<Abstract<R>, String>: ToOCaml<Result<DynBox<R>, String>>,
{
let Abstract(rust) = var.to_rust(cr);
body(rust)
Expand All @@ -72,7 +71,6 @@ where
T: Clone + 'static,
R: 'static,
E: std::string::ToString,
Result<Abstract<R>, String>: ToOCaml<Result<DynBox<R>, String>>,
{
let Abstract(rust) = var.to_rust(cr);
body(cr, rust)
Expand All @@ -93,7 +91,6 @@ where
T2: Clone + 'static,
R: 'static,
E: std::string::ToString,
Result<Abstract<R>, String>: ToOCaml<Result<DynBox<R>, String>>,
{
let Abstract(rust1) = v1.to_rust(cr);
let Abstract(rust2) = v2.to_rust(cr);
Expand Down Expand Up @@ -223,8 +220,8 @@ unsafe impl FromOCaml<TimeUnit> for PolarsTimeUnit {
}
}

unsafe impl ToOCaml<TimeUnit> for PolarsTimeUnit {
fn to_ocaml<'a>(&self, cr: &'a mut OCamlRuntime) -> OCaml<'a, TimeUnit> {
unsafe impl ToOCaml<TimeUnit> for &PolarsTimeUnit {
fn to_ocaml<'a>(self, cr: &'a mut OCamlRuntime) -> OCaml<'a, TimeUnit> {
let PolarsTimeUnit(timeunit) = self;
ocaml_alloc_variant! {
cr, timeunit => {
Expand Down Expand Up @@ -288,8 +285,8 @@ unsafe fn ocaml_value<T>(cr: &OCamlRuntime, n: i32) -> OCaml<T> {
unsafe { OCaml::new(cr, OCaml::of_i32(n).raw()) }
}

unsafe impl ToOCaml<DataType> for PolarsDataType {
fn to_ocaml<'a>(&self, cr: &'a mut OCamlRuntime) -> OCaml<'a, DataType> {
unsafe impl ToOCaml<DataType> for &PolarsDataType {
fn to_ocaml<'a>(self, cr: &'a mut OCamlRuntime) -> OCaml<'a, DataType> {
let PolarsDataType(datatype) = self;
// We expand out the macro here since we need to do some massaging of the
// values to get things into the right shape to convert to OCaml values
Expand Down Expand Up @@ -432,8 +429,8 @@ unsafe impl FromOCaml<FillNullStrategy> for PolarsFillNullStrategy {
}
}

unsafe impl ToOCaml<FillNullStrategy> for PolarsFillNullStrategy {
fn to_ocaml<'a>(&self, cr: &'a mut OCamlRuntime) -> OCaml<'a, FillNullStrategy> {
unsafe impl ToOCaml<FillNullStrategy> for &PolarsFillNullStrategy {
fn to_ocaml<'a>(self, cr: &'a mut OCamlRuntime) -> OCaml<'a, FillNullStrategy> {
let PolarsFillNullStrategy(fill_null_strategy) = self;

// We expand out the macro here since we need to do some massaging of the
Expand Down Expand Up @@ -474,8 +471,8 @@ unsafe impl FromOCaml<InterpolationMethod> for PolarsInterpolationMethod {
}
}

unsafe impl ToOCaml<InterpolationMethod> for PolarsInterpolationMethod {
fn to_ocaml<'a>(&self, cr: &'a mut OCamlRuntime) -> OCaml<'a, InterpolationMethod> {
unsafe impl ToOCaml<InterpolationMethod> for &PolarsInterpolationMethod {
fn to_ocaml<'a>(self, cr: &'a mut OCamlRuntime) -> OCaml<'a, InterpolationMethod> {
let PolarsInterpolationMethod(interpolation_method) = self;

ocaml_alloc_polymorphic_variant! {
Expand All @@ -502,8 +499,8 @@ unsafe impl FromOCaml<WindowMapping> for PolarsWindowMapping {
}
}

unsafe impl ToOCaml<WindowMapping> for PolarsWindowMapping {
fn to_ocaml<'a>(&self, cr: &'a mut OCamlRuntime) -> OCaml<'a, WindowMapping> {
unsafe impl ToOCaml<WindowMapping> for &PolarsWindowMapping {
fn to_ocaml<'a>(self, cr: &'a mut OCamlRuntime) -> OCaml<'a, WindowMapping> {
let PolarsWindowMapping(window_mapping) = self;

unsafe {
Expand Down Expand Up @@ -536,8 +533,8 @@ unsafe impl FromOCaml<RankMethod> for PolarsRankMethod {
}
}

unsafe impl ToOCaml<RankMethod> for PolarsRankMethod {
fn to_ocaml<'a>(&self, cr: &'a mut OCamlRuntime) -> OCaml<'a, RankMethod> {
unsafe impl ToOCaml<RankMethod> for &PolarsRankMethod {
fn to_ocaml<'a>(self, cr: &'a mut OCamlRuntime) -> OCaml<'a, RankMethod> {
let PolarsRankMethod(rank_method) = self;
ocaml_alloc_polymorphic_variant! {
cr, rank_method => {
Expand Down Expand Up @@ -730,11 +727,11 @@ unsafe impl<T: 'static + Clone> FromOCaml<DynBox<T>> for Abstract<T> {
}
}

unsafe impl<T: 'static + Clone> ToOCaml<DynBox<T>> for Abstract<T> {
fn to_ocaml<'a>(&self, cr: &'a mut OCamlRuntime) -> OCaml<'a, DynBox<T>> {
unsafe impl<T: 'static> ToOCaml<DynBox<T>> for Abstract<T> {
fn to_ocaml<'a>(self, cr: &'a mut OCamlRuntime) -> OCaml<'a, DynBox<T>> {
// TODO: I don't fully understand why ToOCaml takes a &self, since that
// prevents us from using box_value without a clone() call.
OCaml::box_value(cr, self.0.clone())
OCaml::box_value(cr, self.0)
}
}

Expand All @@ -754,8 +751,8 @@ unsafe impl FromOCaml<DummyBoxRoot> for DummyBoxRoot {
}
}

unsafe impl ToOCaml<DummyBoxRoot> for DummyBoxRoot {
fn to_ocaml<'a>(&self, cr: &'a mut OCamlRuntime) -> OCaml<'a, DummyBoxRoot> {
unsafe impl ToOCaml<DummyBoxRoot> for &DummyBoxRoot {
fn to_ocaml<'a>(self, cr: &'a mut OCamlRuntime) -> OCaml<'a, DummyBoxRoot> {
self.0.get(cr)
}
}
Expand All @@ -781,12 +778,12 @@ impl DummyBoxRoot {

pub struct OCamlIntable<T>(pub T);

unsafe impl<T> ToOCaml<OCamlInt> for OCamlIntable<T>
unsafe impl<T> ToOCaml<OCamlInt> for &OCamlIntable<T>
where
T: TryInto<i64> + Copy,
<T as TryInto<i64>>::Error: Debug,
{
fn to_ocaml<'a>(&self, _cr: &'a mut OCamlRuntime) -> OCaml<'a, OCamlInt> {
fn to_ocaml<'a>(self, _cr: &'a mut OCamlRuntime) -> OCaml<'a, OCamlInt> {
OCaml::of_i64(self.0.try_into().expect("Couldn't convert to i64"))
.expect("Number couldn't fit in OCaml integer")
}
Expand Down
Loading