fix: Respect categorical dtype capacity when sampling - #404
Merged
Oliver Borchert (borchero) merged 1 commit intoSep 18, 2026
Merged
Conversation
Oliver Borchert (borchero)
requested review from
Andreas Albert (AndreasAlbertQC) and
Daniel Elsner (delsner)
as code owners
September 18, 2026 00:33
Copilot started reviewing on behalf of
Oliver Borchert (borchero)
September 18, 2026 00:34
View session
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Oliver Borchert (borchero)
deleted the
fix/categorical-sampling-capacity
branch
September 18, 2026 00:39
Contributor
There was a problem hiding this comment.
🟢 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
UInt8categorical 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 |
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
Sampling a categorical column backed by
UInt8can fail because the current string range contains 702 distinct values, exceeding the physical dtype's capacity.