Repository navigation
Add custom_data argument to px.histogram - #5811
Open
bhaskargurram-ai wants to merge 1 commit into
Open
bhaskargurram-ai wants to merge 1 commit into
bhaskargurram-ai wants to merge 1 commit into
Conversation
Every other Plotly Express function that builds a trace from rows of the data frame accepts custom_data, but histogram() never did. The core already handles the argument generically (it is how hover_data columns reach customdata for the other functions), so adding the parameter is enough: the selected columns are stored per input row in the trace's customdata and are available in the events the figure emits, which is what Dash callbacks and selection handlers need. Closes plotly#3859
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to issue
Closes #3859
Description of change
Adds the
custom_dataargument topx.histogram. Every other Plotly Express function that builds a trace from rows of the data frame already accepts it, and as @emilykl noted in #3859, "I don't see any reason whycustom_datashouldn't be an argument topx.histogram(), I assume it was just an oversight."The core already handles
custom_datagenerically (it is howhover_datacolumns reachcustomdatafor the other functions), so adding the parameter tohistogram()is the whole change. The selected columns are stored per input row in the trace'scustomdata, where Dash callbacks and selection handlers can read them; the hover label is unchanged, since histogram bins are aggregates. The docstring entry comes from_doc.pylike the other functions.Demo
On
mainthe same call raisesTypeError: histogram() got an unexpected keyword argument 'custom_data'.Testing strategy
Added
test_custom_data_histogramtotests/test_optional/test_px/test_px.py, parametrized over the pandas, pyarrow and polars backends. It checks thatcustomdataisNoneby default, thatcustom_data=["tip", "day"]gives one row per input row with the right values, that the hover template is unaffected, and that withcolor="sex"each trace carries the custom data of its own rows. The px test module passes with the change (ruff format --check .clean).Additional information
Marginal traces are not affected: the marginal histogram specs only carry their axis column.
Guidelines