question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Impossible to change FactorRange to a lower dimension with different number of factors

See original GitHub issue

Initially reported at https://discourse.bokeh.org/t/y-ticks-y-range-error-while-changing-from-2-dimensional-x-range-factors-to-1-dimensional/5106

ALL software version info (bokeh, python, notebook, OS, browser, any other relevant packages)

Bokeh 2.0.1

Description of expected behavior and the observed behavior

It should be possible to switch between factors of a FactorRange without any issues.

Complete, minimal, self-contained example code that reproduces the issue

from bokeh.io import show
from bokeh.layouts import column
from bokeh.models import Button, CustomJS, ColumnDataSource, FactorRange
from bokeh.plotting import figure

fig = figure(x_range=FactorRange(factors=[('a', 'b'), ('b', 'c')]))

ds = ColumnDataSource(data=dict(x=[['a', 'b'], ['b', 'c']], y=[1, 2]))
fig.vbar(x='x', top='y', source=ds)

b = Button(label="Switch to single level")

b.js_on_click(CustomJS(args=dict(fig=fig, ds=ds),
                       code="""\
                           fig.x_range.factors = ['a'];
                           ds.data = {x: ['a'], y: [1]};
                           ds.change.emit();
                       """))

show(column(b, fig))

At least one of the causes is that FactorRange.tops is not updated if we switch to 1D factors from 2D or 3D factors: https://github.com/bokeh/bokeh/blob/cd74b12ed245c3d53c8bf21420de0f14979aebd0/bokehjs/src/lib/models/ranges/factor_range.ts#L240 There seems to be at least one other issue because the error that you see may depend on the order of the instructions within the CustomJS.code above. Seems like a race condition.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:14 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
mattpapcommented, Apr 5, 2020

In bokeh this:

plot.x_range.update(start=1, end=2)

and in bokehjs:

plot.x_range.setv({start: 1, end: 2})

are equivalent to:

plot.x_range.start = 0
plot.y_range.start = 0

when it comes to client-server updates (signals/events are a separate concern). If you look at the implementation, you will see a simple for loop distributing over changed properties in both cases. Those for loops need to be folded to allow pushing multiple changes in one protocol-level change event.

Additionally it would be nice to allow to synchronize a block of code like this:

plot.x_range.start = 0
plot.y_range.start = 0

so that one isn’t forced to use setv() or update(). I already implemented this locally and it will be part of bokeh 3.0. In bokehjs one will write:

plot.synchronized(() => {
  plot.x_range.start = 0
  plot.y_range.start = 0
})

and in bokeh there will be a context manager (as a substitute for multiline lambdas).

1reaction
bryevdvcommented, Apr 5, 2020

Yes, I mean that we should take existing APIs and improve them. Especially since Document is the correct place for these kind of synchronizations, not Plot (there may not be a plot at all, or changes that span multiple Plots). AFAICT there is an obvious place for unhold to generate a single protocol message instead of looping at the end.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ranges — Bokeh 2.4.0 Documentation
Models for describing different kinds of ranges of values in different kinds of spaces (e.g., continuous or categorical) and with options for “auto...
Read more >
Dimensional Factor - an overview | ScienceDirect Topics
The dimensional stability of materials depends on several factors such as density and ... Using Eq. (4.14) it is possible to modify the...
Read more >
Comparison of dimension reduction techniques in the analysis ...
Online analysis with mass spectrometers produces complex data sets, consisting of mass spectra with a large number of chemical compounds ...
Read more >
11 Dimensionality reduction techniques you should know in ...
Dimensionality reduction is very useful for factor analysis — This is a useful ... Both methods reduce the number of dimensions but in...
Read more >
Using Horn's Parallel Analysis Method in Exploratory Factor ...
In this study, the number of factors obtained from parallel analysis, ... The exploratory aim of factor analysis defines lower dimensions of measuring....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found