Skip to content

Commit

Permalink
fix: should not use unwrap() in RPolarsLazyFrame.cast (#1224)
Browse files Browse the repository at this point in the history
Co-authored-by: Etienne Bacher <52219252+etiennebacher@users.noreply.github.com>
  • Loading branch information
eitsupi and etiennebacher authored Sep 4, 2024
1 parent bf36b01 commit 20ddf35
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,5 @@ Collate:
'zzz.R'
Config/rextendr/version: 0.3.1
VignetteBuilder: knitr
Config/polars/LibVersion: 0.42.1
Config/polars/LibVersion: 0.42.2
Config/polars/RustToolchainVersion: nightly-2024-07-26
13 changes: 9 additions & 4 deletions src/rust/src/lazy/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,13 +695,18 @@ impl RPolarsLazyFrame {
use polars_core::prelude::InitHashMaps;
use polars_core::prelude::PlHashMap;

let dtypes = dtypes.into_hashmap();
let dtypes = dtypes
.iter()
.map(|(k, v)| {
let data_type = robj_to!(RPolarsDataType, v)?;
Ok(pl::Field::new(k, data_type.0))
})
.collect::<RResult<Vec<_>>>()?;
let mut cast_map = PlHashMap::with_capacity(dtypes.len());
// TODO: this panicks if conversion to Polars Datatype fails but we can't use `?` in this closure
cast_map.extend(
dtypes
.into_iter()
.map(|(k, v)| (k.as_ref(), robj_to!(RPolarsDataType, v).unwrap().0)),
.iter()
.map(|f| (f.name().as_ref(), f.data_type().clone())),
);
Ok(self.0.clone().cast(cast_map, strict).into())
}
Expand Down

0 comments on commit 20ddf35

Please sign in to comment.