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

fix: Keeps Enum order when converting to R #1252

Merged
merged 11 commits into from
Oct 19, 2024
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Suggests:
nanoarrow (>= 0.6.0),
nycflights13,
patrick,
quickcheck,
pillar,
rlang,
rmarkdown,
Expand Down Expand Up @@ -116,7 +117,7 @@ Collate:
'sql.R'
'vctrs.R'
'zzz.R'
Config/rextendr/version: 0.3.1
Config/rextendr/version: 0.3.1.9000
andyquinterom marked this conversation as resolved.
Show resolved Hide resolved
VignetteBuilder: knitr
Config/polars/LibVersion: 0.43.0
Config/polars/RustToolchainVersion: nightly-2024-09-19
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## Polars R Package 0.20.0

- Updated rust-polars to 0.43.1 (#1230).
- Maintains level order when converting Enums to factors (#1252, @andyquinterom)
andyquinterom marked this conversation as resolved.
Show resolved Hide resolved

### Breaking changes

Expand Down
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
Loading
Loading