Skip to content

Conversation

@mattijn
Copy link
Contributor

@mattijn mattijn commented Nov 1, 2025

Attempt to fix #3891.

This PR now emits a warning when identical parameters are merged during concatenation to alert users to unintended linking.

With #3851, we now use a hash-based naming for parameters and views for deterministic names and thread safety, but I said in this comment #3851 (comment) that duplicate explicit names will raise an error to catch potential mistakes.

  • Identical parameters gets deduplicated only when a hash-based name was derived
  • Explicit parameter names are still supported, but duplicate explicit names will raise an error to catch potential mistakes.

But I found that this only works for a single chart (via add_params): hash-based duplicates are dropped; explicit duplicates raise. During concatenation (via _combine_subchart_params) all identical parameters (hash-based and explicit) are deduplicated and a warning is raised, so when using explicit names there is no raising of error.

Eg. this (explicit name for interactive selection paramater, that becomes identical during concatenation):

import altair as alt
from altair.datasets import data

cars = data.cars.url

chart = (
    alt.Chart(cars)
    .mark_point()
    .encode(x="Horsepower:Q", y="Miles_per_Gallon:Q")
    .interactive(name="MY_CHART")
)
(chart & chart).to_dict()

Returns

/var/folders/b3/pctp5dwn6t7fm1t4sc4tknb00000gp/T/ipykernel_88674/3413242154.py:12: 
UserWarning: Automatically deduplicated selection parameter with identical configuration. 
If you want independent parameters, explicitly name them differently (e.g., name='param1', name='param2'). 
See https://github.com/vega/altair/issues/3891
  (chart & chart).to_dict()
{'config': {'view': {'continuousWidth': 300, 'continuousHeight': 300}},
 'vconcat': [{'mark': {'type': 'point'},
   'encoding': {'x': {'field': 'Horsepower', 'type': 'quantitative'},
    'y': {'field': 'Miles_per_Gallon', 'type': 'quantitative'}},
   'name': 'view_6e7cfb454e831ee6_0'},
  {'mark': {'type': 'point'},
   'encoding': {'x': {'field': 'Horsepower', 'type': 'quantitative'},
    'y': {'field': 'Miles_per_Gallon', 'type': 'quantitative'}},
   'name': 'view_6e7cfb454e831ee6_1'}],
 'data': {'url': 'https://cdn.jsdelivr.net/npm/[email protected]/data/cars.json'},
 'params': [{'name': 'MY_CHART',
   'select': {'type': 'interval', 'encodings': ['x', 'y']},
   'bind': 'scales',
   'views': ['view_6e7cfb454e831ee6_0', 'view_6e7cfb454e831ee6_1']}],
 '$schema': 'https://vega.github.io/schema/vega-lite/v6.1.0.json'}

And this (explicit identical name for parameters):

from altair.datasets import data

cars = data.cars.url
param_opacity = alt.param(value=1, name='MY_PARAM')
param_size = alt.param(value=1, name='MY_PARAM')

# Create chart with same parameter added twice
chart = (
    alt.Chart(cars)
    .mark_circle(opacity=param_opacity, size=param_size)
    .encode(x="Horsepower:Q", y="Miles_per_Gallon:Q", color="Origin:N")
    .add_params(param_opacity, param_size)
)

Returns

ValueError: Duplicate explicit parameter name: MY_PARAM

I'm merely documenting this. I don't know what to do with it, since I'm not really sure if we can improve this situation any better.

It would be great if you could have a look to @joelostblom!

@mattijn mattijn changed the title add warning for deduplications feat: add warning for deduplications Nov 1, 2025
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.

Altair incorrectly combines parameters with the same properties instead of assigning them unique IDs

2 participants