Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed categorical_order_by used with array_like #157

Merged
merged 5 commits into from Mar 30, 2023

Conversation

vanHekthor
Copy link
Contributor

@vanHekthor vanHekthor commented Mar 25, 2023

What this PR does / why we need it:
Fixes bug with categorical_order_by and numpy arrays / pandas series
Which issue(s) this PR fixes

Fixes #74

Special notes for your reviewer:
While writing the tests I discovered some weirdness in the chart data:

  • the data for bar charts (and all other plots using PlotMixedTypeXY._construct_source) is in order of the specified ordering
  • the scatter data is in the initial order (i.e. not ordered)

Nevertheless, in the chart, the data is displayed correctly, because not the order of the chart data defines the category order but the order of the factors of bokeh.plotting.figure.x_range (vertical) or bokeh.plotting.figure.y_range (horizontal).
And that is set by PlotMixedTypeXY._set_categorical_axis_default_factors.

What happens is that:

  • for plots using PlotMixedTypeXY._construct_source, the data gets sorted and then the x_range is set accordingly
  • for a scatter plot, factors are sorted and x_range.factors is set but the actual data does not get sorted

So it seems like sorting the actual data (like in _construct_source) is unnecessary as bokeh does not consider the order of the data itself but instead maps the observations to the corresponding factors in the x_range.

I think this can be addressed in a separate issue.

Release note:

Support ordering categories using array_like (numpy array, pandas series)

@vanHekthor vanHekthor changed the title Fix categorical order by Fixed categorical_order_by used with array_like Mar 25, 2023
@iampelle iampelle changed the base branch from master to Release-4.0.2 March 30, 2023 10:12
@iampelle iampelle merged commit 5e9e710 into spotify:Release-4.0.2 Mar 30, 2023
3 checks passed
iampelle added a commit that referenced this pull request Mar 30, 2023
* Fixed categorical_order_by used with array_like (#157)

* Fix categorical_order_by check for scatter plot

* Fix categorical_order_by check for _construct_source

* Refactor category sorting in _construct_source

* Add tests for categorical_order_by

* Correct scatter test (#158)

* Update version in init

* Update HISTORY.rst

---------

Co-authored-by: Quoc Duong Bui <35042166+vanHekthor@users.noreply.github.com>
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.

Plot breaks if np.array passed to categorical_order_by
2 participants