feat: Allow comparing different categoricals by casting to strings - #49
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #49 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 13 13
Lines 1127 1129 +2
=========================================
+ Hits 1127 1129 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Copilot started reviewing on behalf of
Marius Merkle (MariusMerkleQC)
July 28, 2026 11:40
View session
Contributor
There was a problem hiding this comment.
Pull request overview
Adds support for comparing pl.Categorical columns that have different category sets by falling back to string comparison, aligning categorical behavior with existing handling for mismatched enums and enum↔categorical comparisons.
Changes:
- Detect categoricals with differing category metadata and cast both sides to
pl.Stringfor comparison. - Extend element-wise comparison detection to treat “different categoricals” similarly to “different enums”.
- Add a regression test covering categorical comparisons with differing category metadata.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
diffly/_conditions.py |
Adds “different categoricals” detection and routes those comparisons through the existing string-cast fallback path. |
tests/test_conditions.py |
Introduces a new test case for comparing categoricals with different category metadata. |
Comments suppressed due to low confidence (2)
diffly/_conditions.py:163
- The inline comment is now slightly inaccurate: the branch also handles categoricals with different category sets (not just enums, or enum/categorical mixes). Updating it will keep future maintenance and debugging clearer.
# Enums with different categories as well as enums and categoricals
# can't be compared directly.
# Fall back to comparison of strings.
tests/test_conditions.py:592
- After making one row equal, the expected results should include a True. Adding an explicit _needs_element_wise_comparison assertion also exercises the new dtype-difference detection logic directly.
# Assert
assert actual.to_list() == [False, False]
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Marius Merkle (MariusMerkleQC)
marked this pull request as ready for review
July 28, 2026 11:48
Marius Merkle (MariusMerkleQC)
requested review from
EgeKaraismailogluQC and
Oliver Borchert (borchero)
as code owners
July 28, 2026 11:48
Oliver Borchert (borchero)
approved these changes
Jul 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
We should allow comparing
pl.Categoricalwith different sets of categoriespl.Categoriesby casting topl.String. We already have a similar approach when comparingpl.Enumpl.Enumandpl.CategoricalThe schema section will still show that the categorical type changed.