Skip to content

alt.datum and alt.value generates incorrect error messages #2913

@joelostblom

Description

@joelostblom

Originally reported in #2883 (comment). When using the datum encoding then the message is incorrect:

alt.Chart().mark_point().encode(x=alt.datum(1, wrong_name=1))
SchemaValidationError: Invalid specification

        altair.vegalite.v5.schema.channels.X, validating 'additionalProperties'

        Additional properties are not allowed ('datum', 'wrong_name' were unexpected)

'datum' should not be included above as an incorrect property to the X channel, instead wrong_name should be mentioned as an incorrect parameter to datum. The way to handle this is probably with special error checking inside the datum function (although maybe it needs to also consider which encoding channel it is used for?).


Also mentioned in #2568 (comment) for alt.value. This can look more confusing now that the error message gives parameter hints:

I found one spec that gives an incorrect hint:

import altair as alt
from vega_datasets import data
cars = data.cars.url

alt.Chart(cars).mark_point().encode(
    x='Acceleration:Q',
    y='Horsepower:Q',
    color=alt.value(1)  # should be eg. alt.value('red')
)
SchemaValidationError: `Color` has no parameter named 'value'

Existing parameter names are:
shorthand      bin         legend   timeUnit   
aggregate      condition   scale    title      
bandPosition   field       sort     type       

See the help for `Color` to read the full description of these parameters

It is allowed to use alt.value() in this context, but in this case it should be a string and not a number.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions