fix: handle missing scatter_data in plot_centiles_advanced#374
Merged
contsili merged 2 commits intoamarquand:devfrom Feb 19, 2026
Merged
Conversation
Two fixes for plot_centiles_advanced crashing when scatter_data is None: 1. Multi-covariate models: the midpoint computation for non-plotted covariates used scatter_data.X unconditionally. Now falls back to the midpoint of the model's covariate range when scatter_data is not provided. 2. Saving plots: plotname was only defined inside the 'if scatter_data' block, causing a NameError when save_dir was set without scatter_data. Now plotname has a default value before the scatter_data check.
Collaborator
|
the same errors happen with the |
Author
|
@contsili good point! thanks! I encountered this when using the notebooks where plot_centiles_advanced was used so i overlooked plot_centiles. |
- Avoid errors when scatter_data is None - Use the mean of scatter_data for other covariates when available (same logic as with the plot_centiles_advanced)
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.
Fix: handle missing
scatter_datainplot_centiles_advancedCloses #373
Problem
plot_centiles_advancedcrashes when called withoutscatter_datain two scenarios:plotnameis only defined insideif scatter_data:, but thesave_dirlogic at the end uses it unconditionally →NameErrorscatter_data.Xunconditionally →AttributeErrorChanges
Minimal two-line fix in
plotter.py:Default
plotname: Addedplotname = f"centiles_{response_var}"before the
if scatter_data:block so it always has a value when saving.Covariate fallback: When
scatter_dataisNone, the non-plotted covariate value now falls back to the midpoint of the model's stored covariate range instead of trying to compute the mean from scatter data.Verification
After the fix, the following calls work without error: