Skip to content

fix: Respect categorical dtype capacity when sampling - #404

Merged
Oliver Borchert (borchero) merged 1 commit into
mainfrom
fix/categorical-sampling-capacity
Sep 18, 2026
Merged

Oliver Borchert (borchero) merged 1 commit into
mainfrom
fix/categorical-sampling-capacity

Conversation

@borchero

@borchero Oliver Borchert (borchero) commented Sep 18, 2026

Copy link
Copy Markdown
Member

Motivation

Sampling a categorical column backed by UInt8 can fail because the current string range contains 702 distinct values, exceeding the physical dtype's capacity.

@codecov

codecov Bot commented Sep 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (a823755) to head (4a868ff).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #404   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           46        46           
  Lines         2615      2616    +1     
=========================================
+ Hits          2615      2616    +1     

☔ 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.

@borchero
Oliver Borchert (borchero) merged commit 05ce6d6 into main Sep 18, 2026
33 of 34 checks passed
@borchero
Oliver Borchert (borchero) deleted the fix/categorical-sampling-capacity branch September 18, 2026 00:39

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.

🟢 Approval recommended

The implementation and test coverage address the capacity issue; only a minor test-format nit remains.

Pull request overview

Fixes categorical sampling so generated values respect the backing physical dtype capacity.

Changes:

  • Limits UInt8 categorical samples to single-letter values.
  • Adds parameterized coverage for physical types, nullability, categories, and sample sizes.
File summaries
File Summary
tests/columns/test_sample.py Adds categorical sampling coverage; one test should include Arrange/Act/Assert comments.
dataframely/columns/categorical.py Adjusts sampled string cardinality based on categorical capacity.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +189 to +200
categories = (
pl.Categories("sample", physical=physical) if explicit_categories else physical
)
schema = create_schema("test", {"a": dy.Categorical(categories, nullable=nullable)})
column = schema.columns()["a"]
samples = sample_and_validate(column, generator, n=n)
assert len(samples) == n
assert samples.dtype == column.dtype
assert samples.to_physical().dtype == physical
assert samples.drop_nulls().n_unique() <= (256 if physical == pl.UInt8 else 702)
if n:
assert samples.is_null().any() == nullable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants