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

Address issue #1105 #1164

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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 {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that FromRobj was removed in favor of TryFrom

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);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modifying attributes modifies in place. Previously, this didn't require a mutable reference giving false confidence. Now it requires a mutable reference. Additionally, the same type is returned after modifying the attributes. So if you use set_class() or set_attrib() on a List it will return a mut List.

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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We increment the reference counter and convert into an Robj for compatibility with this function. I did not want to modify the function itself.

}

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()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Increment reference counter to go from &mut Robj to Robj and likewise below.

}),
_ => 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())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly from Result<&mut Robj, E> to Result<Robj, E>

.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
Loading