Skip to content

Commit

Permalink
fix: Keeps Enum order when converting to R
Browse files Browse the repository at this point in the history
  • Loading branch information
andyquinterom committed Oct 9, 2024
1 parent 61fb332 commit 9eadb26
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/rust/src/conversion_s_to_r.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@ pub fn pl_series_to_list(
.set_class(["rpolars_raw_list", "list"])
.expect("this class label is always valid")
}),
Enum(_, _) => s
.categorical()
.map(|ca| extendr_api::call!("factor", ca.iter_str().collect_robj()).unwrap()),
Enum(_, _) => s.categorical().map(|ca| {
let levels = ca.unique().unwrap().iter_str().collect_robj();
let values = ca.iter_str().collect_robj();
extendr_api::call!("factor", values, levels).unwrap()
}),
Categorical(_, _) => s
.categorical()
.map(|ca| extendr_api::call!("factor", ca.iter_str().collect_robj()).unwrap()),
Expand Down

0 comments on commit 9eadb26

Please sign in to comment.