Skip to content

Commit

Permalink
Address issue pola-rs#1105
Browse files Browse the repository at this point in the history
  • Loading branch information
JosiahParry committed Jul 7, 2024
1 parent 471c070 commit b4005ea
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
14 changes: 7 additions & 7 deletions src/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ opt-level = 3 # was 1 to support 1.66, but since 1.70 is needed anyway it does n
opt-level = 3

[dependencies]
extendr-api = { git = "https://github.com/extendr/extendr", rev = "1895bfc8ee22347665900caa0e48da4f0b13232f", default-features = false, features = [
extendr-api = { git = "https://github.com/extendr/extendr", rev = "928aee2c3ee1b1fc5b0d4b449de3807da30ecd8f", default-features = false, features = [
"result_list",
"serde",
] }
Expand Down
5 changes: 3 additions & 2 deletions src/rust/src/arrow_interop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ pub enum RArrowArrayClass {
NanoArrowArray,
}

impl<'a> FromRobj<'a> for RArrowArrayClass {
fn from_robj(robj: &Robj) -> std::result::Result<Self, &'static str> {
impl TryFrom<&Robj> for RArrowArrayClass {
type Error = &'static str;
fn try_from(robj: &Robj) -> std::result::Result<Self, &'static str> {
if robj.inherits("nanoarrow_array") {
Ok(RArrowArrayClass::NanoArrowArray)
} else if robj.inherits("Array") {
Expand Down
2 changes: 1 addition & 1 deletion src/rust/src/arrow_interop/to_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn arrow_array_to_rust(arrow_array: Robj) -> Result<ArrayRef, String> {
)
};

RArrowArrayClass::from_robj(&arrow_array)?
RArrowArrayClass::try_from(&arrow_array)?
.get_package()
.get_export_array_func()?
.call(pairlist!(&arrow_array, ext_a, ext_s))?;
Expand Down
5 changes: 3 additions & 2 deletions src/rust/src/conversion_r_to_s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,11 @@ fn recursive_robjname2series_tree(x: &Robj, name: &str) -> pl::PolarsResult<Seri
}

Rtype::Raw => {
let rpolars_raw_list = list!(x)
let mut binding = list!(x);
let rpolars_raw_list = binding
.set_class(["rpolars_raw_list", "list"])
.map_err(|err| pl::polars_err!(ComputeError: err.to_string()))?;
recursive_robjname2series_tree(&rpolars_raw_list, name)
recursive_robjname2series_tree(&rpolars_raw_list.clone().into_robj(), name)
}

Rtype::List if x.inherits("rpolars_raw_list") => {
Expand Down
13 changes: 10 additions & 3 deletions src/rust/src/conversion_s_to_r.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub fn pl_series_to_list(
.collect_robj()
.set_class(&["integer64"])
.expect("internal error could not set class label 'integer64'")
.clone()
}),
_ => Err(pl::PolarsError::InvalidOperation(
"`int64_conversion ` must be one of 'float', 'string', 'bit64'".into(),
Expand Down Expand Up @@ -109,6 +110,7 @@ pub fn pl_series_to_list(
.into_robj()
.set_class(["rpolars_raw_list", "list"])
.expect("this class label is always valid")
.clone()
}),
Enum(_, _) => s
.categorical()
Expand Down Expand Up @@ -181,7 +183,8 @@ pub fn pl_series_to_list(
.into_iter()
.collect_robj()
.set_class(&["Date"])
.expect("internal error: class label Date failed")),
.expect("internal error: class label Date failed")
.clone()),
Null => Ok((extendr_api::NULL).into_robj()),
Time => s
.cast(&Int64)?
Expand All @@ -195,8 +198,9 @@ pub fn pl_series_to_list(
.map(|mut robj| {
robj.set_class(&["PTime"])
.expect("internal error: class label PTime failed")
.clone()
})
.map(|mut robj| robj.set_attrib("tu", "ns"))
.map(|mut robj| robj.set_attrib("tu", "ns").cloned())
.expect("internal error: attr tu failed")
.map_err(|err| {
pl_error::ComputeError(
Expand Down Expand Up @@ -248,9 +252,12 @@ pub fn pl_series_to_list(
.map(|mut robj| {
robj.set_class(&["POSIXct", "POSIXt"])
.expect("internal error: class POSIXct label failed")
.clone()
})
.map(|mut robj| {
robj.set_attrib("tzone", opt_tz.as_ref().map(|s| s.as_str()).unwrap_or(""))
let res = robj
.set_attrib("tzone", opt_tz.as_ref().map(|s| s.as_str()).unwrap_or(""));
res.cloned()
})
.expect("internal error: attr tzone failed")
.map_err(|err| {
Expand Down

0 comments on commit b4005ea

Please sign in to comment.