Skip to content

fix: include all mapped columns in stat transform GROUP BY#240

Closed
cpsievert wants to merge 1 commit intomainfrom
fix/integer-fill-grouping
Closed

fix: include all mapped columns in stat transform GROUP BY#240
cpsievert wants to merge 1 commit intomainfrom
fix/integer-fill-grouping

Conversation

@cpsievert
Copy link
Collaborator

Summary

Fixes #239.

Integer columns mapped to non-positional aesthetics like fill or color were being dropped by stat transforms (e.g., bar's COUNT). This happened because only String/Boolean/Categorical columns were considered "discrete" and added to partition_by — integer columns were skipped, causing them to be excluded from GROUP BY.

Before: DRAW bar MAPPING sex AS x, survived AS fill (where survived is integer 0/1) → validation error because fill column was dropped by stat transform.

After: All non-positional, non-stat-consumed mapped columns are added to partition_by regardless of data type, matching ggplot2's grouping behavior.

Changes

  • src/execute/mod.rs: Renamed add_discrete_columns_to_partition_byadd_mapped_columns_to_partition_by and removed the discreteness filter. Simplified the function signature (removed unused scales and aesthetic_ctx parameters).
  • src/execute/layer.rs, src/execute/position.rs: Updated comments referencing the renamed function.
  • New test: test_bar_with_integer_fill_column verifies integer fill columns survive bar stat transforms.

Test plan

  • New test test_bar_with_integer_fill_column passes
  • All 1221 existing tests pass
  • No compiler warnings

🤖 Generated with Claude Code

Integer columns mapped to non-positional aesthetics like fill/color
were dropped by stat transforms because only String/Boolean/Categorical
columns were added to partition_by. Now all non-positional, non-stat-consumed
mapped columns are included in GROUP BY, matching ggplot2's grouping behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cpsievert
Copy link
Collaborator Author

@thomasp85 Take this with a heavy grain of salt. I haven't investigated this change at all yet -- more so just proposing it to promote awareness and get a conversation going.

@thomasp85
Copy link
Collaborator

I'm very much against this. If you wish to use an integer column then make it discrete (which will make it part of the grouping). You are already saying that you meant for the column to be discrete but it happened to be numeric - the fix is to explicitly make it discrete

DRAW bar 
  MAPPING sex AS x, 
  survived AS fill
SCALE fill VIA bool
-- or
SCALE DISCRETE fill
-- or
SCALE ORDINAL fill

@cpsievert
Copy link
Collaborator Author

Ahh, right, I'm happy to work around this via prompting. This might a good case to keep in mind for #85?

@cpsievert cpsievert closed this Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integer columns mapped to fill/color are dropped by bar stat transform

2 participants