Skip to content

Extend patching to sub-items #6285

Description

@bryevdv

Given the following CDS:

ColumnDataSource(data={
    "foo" : [ 1,    2,    3,    4,    5    ],
    "bar" : [ 1.7,  3.2,  5.8,  9.7,  10.4 ],
    'baz" : [ img1, img2, img3, img4, img5 ],
})

where img1, etc. are 2d NumPy arrays, it is currently possible to patch individual elements using the existing patch format:

patches = {
    'foo' : [ (0, 1) ],
    'bar' : [ (0, -2), (1, 201) ],
    'baz': [ (0, img) ],
}

source.patch(patches)

This suffers from two drawbacks:

  • The indexing scheme does not extend inside 2d images, it is only possible to patch entire images at a time.

  • Even for the 1d case, the indexing scheme is somewhat cumbersome in cases where it is desired to patch contiguous regions of a column.

Propose to extend the patching syntax to accept slices, and to provide a simple mechanism for generating slices:

# patch the first three elements of a 1d column
p1 = patcher[0:3]
patches = { 'foo': (p1, [1, 2, 3] } 

# patch the entire second column of a the 10th image
p2 = patcher[10, :, 2]
patches = { 'baz' : (p2, [...] }

Note: use of an object like patcher with a custom __getitem__ seems necessary, as slice syntax is only available inside indexing brackets.

Would serialize slices slice(1, 10, None) as (1, 10, null). Bounds and consistency checking could occur on the python side, but handling of the slice would occur in BokehJS in the CDS patch method:

https://github.com/bokeh/bokeh/blob/master/bokehjs/src/coffee/models/sources/column_data_source.coffee#L96-L101

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions