Skip to content

feat: Allow comparing different categoricals by casting to strings - #49

Merged
Marius Merkle (MariusMerkleQC) merged 3 commits into
mainfrom
different_categoricals
Jul 28, 2026
Merged

feat: Allow comparing different categoricals by casting to strings#49
Marius Merkle (MariusMerkleQC) merged 3 commits into
mainfrom
different_categoricals

Conversation

@MariusMerkleQC

@MariusMerkleQC Marius Merkle (MariusMerkleQC) commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Motivation

We should allow comparing pl.Categorical with different sets of categories pl.Categories by casting to pl.String. We already have a similar approach when comparing

  • two pl.Enum
  • pl.Enum and pl.Categorical

The schema section will still show that the categorical type changed.

@github-actions github-actions Bot added the enhancement New feature or request label Jul 28, 2026
@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (3769d7d) to head (f087c80).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.String for 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.

Comment thread tests/test_conditions.py Outdated
@MariusMerkleQC
Marius Merkle (MariusMerkleQC) merged commit a0158ce into main Jul 28, 2026
18 checks passed
@MariusMerkleQC
Marius Merkle (MariusMerkleQC) deleted the different_categoricals branch July 28, 2026 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants