Skip to content

Commit

Permalink
by ref
Browse files Browse the repository at this point in the history
  • Loading branch information
c-peters committed Dec 1, 2023
1 parent 0a7d52f commit 9268f27
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions crates/polars-core/src/chunked_array/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,13 @@ impl ChunkCast for Utf8Chunked {
},
Some(rev_map) => {
polars_ensure!(rev_map.is_enum(), InvalidOperation: "casting to a non-enum variant with rev map is not supported for the user");
CategoricalChunked::from_utf8_to_enum(self, rev_map.get_categories().clone())
.map(|ca| {
CategoricalChunked::from_utf8_to_enum(self, rev_map.get_categories()).map(
|ca| {
let mut s = ca.into_series();
s.rename(self.name());
s
})
},
)
},
},
#[cfg(feature = "dtype-struct")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ impl CategoricalChunked {
/// This will error if a string is not in the fixed list of categories
pub fn from_utf8_to_enum(
values: &Utf8Chunked,
categories: Utf8Array<i64>,
categories: &Utf8Array<i64>,
) -> PolarsResult<CategoricalChunked> {
polars_ensure!(categories.null_count() == 0, ComputeError: "categories can not contain null values");

Expand All @@ -570,13 +570,13 @@ impl CategoricalChunked {
opt_s
.map(|s| {
map.get(s).copied().ok_or_else(
|| polars_err!(ComputeError: "value '{}' is not present in Enum: {:?}",s,&categories),
|| polars_err!(ComputeError: "value '{}' is not present in Enum: {:?}",s,categories),
)
})
.transpose()
})
.collect::<Result<UInt32Chunked, PolarsError>>()?;
let rev_map = RevMapping::build_enum(categories);
let rev_map = RevMapping::build_enum(categories.clone());
unsafe {
Ok(CategoricalChunked::from_cats_and_rev_map_unchecked(
ca_idx,
Expand Down

0 comments on commit 9268f27

Please sign in to comment.