Skip to content

Commit

Permalink
fix: Raise if merge non-global categoricals in unpivot (#19826)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Nov 17, 2024
1 parent 5210d99 commit 245d549
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/polars-core/src/utils/supertype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ pub fn merge_dtypes_many<I: IntoIterator<Item = D> + Clone, D: AsRef<DataType>>(
let DataType::Categorical(Some(rm), _) = first_dt else {
unreachable!()
};
polars_ensure!(matches!(rm.as_ref(), RevMapping::Global(_, _, _)), ComputeError: "global string cache must be set to merge categorical columns");

let mut merger = GlobalRevMapMerger::new(rm.clone());

Expand Down
5 changes: 5 additions & 0 deletions py-polars/tests/unit/operations/test_unpivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,8 @@ def test_unpivot_categorical_global() -> None:
"variable": ["1", "1", "2", "2"],
"value": ["a", "b", "b", "c"],
}


def test_unpivot_categorical_raise_19770() -> None:
with pytest.raises(pl.exceptions.ComputeError):
(pl.DataFrame({"x": ["foo"]}).cast(pl.Categorical).unpivot())

0 comments on commit 245d549

Please sign in to comment.