Skip to content

fix: remove invalid stack property from secondary position channels#237

Merged
thomasp85 merged 1 commit intoposit-dev:mainfrom
cpsievert:fix/stack-on-secondary-channels
Mar 18, 2026
Merged

fix: remove invalid stack property from secondary position channels#237
thomasp85 merged 1 commit intoposit-dev:mainfrom
cpsievert:fix/stack-on-secondary-channels

Conversation

@cpsievert
Copy link
Collaborator

Problem

build_layer_encoding emits "stack": null on both primary (y/radius) and secondary (y2/radius2) position channels to disable Vega-Lite's automatic stacking. However, the Vega-Lite v6 schema does not allow stack on secondary channels — only primary position channels support it.

This causes errors when consuming the JSON output with Altair (Python):

  • With validate=False: TypeError: Only chart objects can be used in LayerChart.
  • With validate=True: ValidationError: Additional properties are not allowed ('stack' was unexpected)

Any spec that produces a y2 encoding (bars, areas, segments, ribbons, error bars, etc.) is affected.

Fix

Remove the stack: null insertion on y2/radius2 channels. Only primary position channels (y/radius) need this property — secondary channels don't support independent stacking and inherit behavior from their primary channel.

Test changes

Strengthened test_secondary_channels_have_no_disallowed_properties to:

  • Assert stack is absent from x2/y2 encodings (was not previously checked)
  • Run assert_valid_vegalite() for full Vega-Lite schema validation (was not previously called)

`build_layer_encoding` was emitting `"stack": null` on both primary (y/radius)
and secondary (y2/radius2) position channels. The Vega-Lite v6 schema does not
allow `stack` on secondary channels, causing Altair to reject the spec with
"Only chart objects can be used in LayerChart" (validate=False) or a schema
validation error (validate=True).

Only primary position channels need `stack: null` to disable Vega-Lite's
automatic stacking — secondary channels inherit from the primary.

Also strengthens `test_secondary_channels_have_no_disallowed_properties` to
assert `stack` is absent and to run full Vega-Lite schema validation.

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

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

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

LGTM

@thomasp85 thomasp85 merged commit 922d1b3 into posit-dev:main Mar 18, 2026
18 checks passed
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.

2 participants