spotify / chartify

Python library that makes it easy for data scientists to create charts.
Apache License 2.0
3.52k stars 324 forks source link

Fixed categorical_order_by used with array_like #157

Closed vanHekthor closed 1 year ago

vanHekthor commented 1 year ago

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:

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:

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)