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: Raise if merge non-global categoricals in unpivot #19826

Merged
merged 2 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())