bokeh.core.validation

The validation module provides the capability to perform integrity checks on an entire collection of Bokeh models.

To create a Bokeh visualization, the central task is to assemble a collection model objects from bokeh.plotting into a graph that represents the scene that should be created in the client. It is possible to to this “by hand”, using the model objects directly. However, to make this process easier, Bokeh provides higher level interfaces such as bokeh.plotting for users.

These interfaces automate common “assembly” steps, to ensure a Bokeh object graph is created in a consistent, predictable way. However, regardless of what interface is used, it is possible to put Bokeh models together in ways that are incomplete, or that do not make sense in some way.

To assist with diagnosing potential problems, Bokeh performs a validation step when outputting a visualization for display. This module contains error and warning codes as well as helper functions for defining validation checks.

Error Codes

These define the standard error codes and messages for Bokeh validation checks.

1001 (BAD_COLUMN_NAME)
A glyph has a property set to a field name that does not correspond to any column in the GlyphRenderer’s data source.
1002 (MISSING_GLYPH)
A GlyphRenderer has no glyph configured.
1003 (NO_SOURCE_FOR_GLYPH)
A GlyphRenderer has no data source configured.
1004 (REQUIRED_RANGE)
A Plot is missing one or more required default ranges (will result in blank plot).
1005 (MISSING_GOOGLE_API_KEY)
Google Maps API now requires an API key for all use. See https://developers.google.com/maps/documentation/javascript/get-api-key for more information on how to obtain your own, to use for the api_key property of your Google Map plot .
1006 (NON_MATCHING_DATA_SOURCES_ON_LEGEND_ITEM_RENDERERS)
All data_sources on LegendItem.renderers must match when LegendItem.label is type field.
1007 (MISSING_MERCATOR_DIMENSION)
MercatorTicker and MercatorTickFormatter``models must have their ``dimension property set to 'lat' or 'lon'.
1008 (REQUIRED_SCALE)
A Scale on is missing one or more required default scales (will result in blank plot).
1009 (INCOMPATIBLE_SCALE_AND_RANGE)
A Scale type is incompatible with one or more ranges on the same plot dimension (will result in blank plot).
1010 (CDSVIEW_SOURCE_DOESNT_MATCH)
A GlyphRenderer has a CDSView whose source doesn’t match the GlyphRenderer’s data source.
1011 (MALFORMED_GRAPH_SOURCE)
The GraphSource is incorrectly configured.
1012 (INCOMPATIBLE_MAP_RANGE_TYPE)
Map plots can only support Range1d types, not data ranges.
1013 (INCOMPATIBLE_POINT_DRAW_RENDERER)
The PointDrawTool renderers may only reference XYGlyph models.
1014 (INCOMPATIBLE_BOX_EDIT_RENDERER)
The BoxEditTool renderers may only reference Rect glyph models.
1015 (INCOMPATIBLE_POLY_DRAW_RENDERER)
The PolyDrawTool renderers may only reference MultiLine and Patches glyph models.
1016 (INCOMPATIBLE_POLY_EDIT_RENDERER)
The PolyEditTool renderers may only reference MultiLine and Patches glyph models.
1017 (INCOMPATIBLE_POLY_EDIT_VERTEX_RENDERER)
The PolyEditTool vertex_renderer may only reference XYGlyph models.
1018 (NO_RANGE_TOOL_RANGES)
The RangeTool must have at least one of x_range or y_range configured
1019 (DUPLICATE_FACTORS)
FactorRange must specify a unique list of categorical factors for an axis.
1020 (BAD_EXTRA_RANGE_NAME)
An extra range name is configured with a name that does not correspond to any range.
1021 (EQUAL_SLIDER_START_END)
noUiSlider most have a nonequal start and end.
9999 (EXT)
Indicates that a custom error check has failed.

Warning Codes

These define the standard warning codes and messages for Bokeh validation checks.

1000 (MISSING_RENDERERS)
A Plot object has no renderers configured (will result in a blank plot).
1002 (EMPTY_LAYOUT)
A layout model has no children (will result in a blank layout).
1004 (BOTH_CHILD_AND_ROOT)
Each component can be rendered in only one place, can’t be both a root and in a layout.
9999 (EXT)
Indicates that a custom warning check has failed.

Helper Functions

These helper functions can be used to perform integrity checks on collections of Bokeh models, or mark methods on Models as warning or error checks.

check_integrity(models)[source]

Apply validation and integrity checks to a collection of Bokeh models.

Parameters:models (seq[Model]) – a collection of Models to test
Returns:None

This function will emit log warning and error messages for all error or warning conditions that are detected. For example, layouts without any children will trigger a warning:

>>> empty_row = Row

>>> check_integrity([empty_row])
W-1002 (EMPTY_LAYOUT): Layout has no children: Row(id='2404a029-c69b-4e30-9b7d-4b7b6cdaad5b', ...)
error(code_or_name)[source]

Decorator to mark a validator method for a Bokeh error condition

Parameters:code_or_name (int or str) – a code from bokeh.validation.errors or a string label for a custom check
Returns:decorator for Bokeh model methods
Return type:callable

The function that is decorated should have a name that starts with _check, and return a string message in case a bad condition is detected, and None if no bad condition is detected.

Examples:

The first example uses a numeric code for a standard error provided in bokeh.validation.errors. This usage is primarily of interest to Bokeh core developers.

from bokeh.validation.errors import REQUIRED_RANGES

@error(REQUIRED_RANGES)
def _check_no_glyph_renderers(self):
    if bad_condition: return "message"

The second example shows how a custom warning check can be implemented by passing an arbitrary string label to the decorator. This usage is primarily of interest to anyone extending Bokeh with their own custom models.

@error("MY_CUSTOM_WARNING")
def _check_my_custom_warning(self):
    if bad_condition: return "message"
warning(code_or_name)[source]

Decorator to mark a validator method for a Bokeh error condition

Parameters:code_or_name (int or str) – a code from bokeh.validation.errors or a string label for a custom check
Returns:decorator for Bokeh model methods
Return type:callable

The function that is decorated should have a name that starts with _check, and return a string message in case a bad condition is detected, and None if no bad condition is detected.

Examples:

The first example uses a numeric code for a standard warning provided in bokeh.validation.warnings. This usage is primarily of interest to Bokeh core developers.

from bokeh.validation.warnings import MISSING_RENDERERS

@warning(MISSING_RENDERERS)
def _check_no_glyph_renderers(self):
    if bad_condition: return "message"

The second example shows how a custom warning check can be implemented by passing an arbitrary string label to the decorator. This usage is primarily of interest to anyone extending Bokeh with their own custom models.

@warning("MY_CUSTOM_WARNING")
def _check_my_custom_warning(self):
    if bad_condition: return "message"