Repository navigation
Accept None elements in color, number and angle arrays so from_json loads figures with NaN - #5856
Open
Thanatos9404 wants to merge 2 commits into
Open
Thanatos9404 wants to merge 2 commits into
Thanatos9404 wants to merge 2 commits into
Conversation
to_json writes NaN as null and from_json loads it back as None, which ColorValidator, NumberValidator and AngleValidator rejected inside lists, so figures with NaN in these arrays could not be loaded again. Keep None elements in arrays; scalars are unchanged.
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 #4280
Description of change
to_jsonwrites NaN asnull, andfrom_jsonloads that back asNone.ColorValidator,NumberValidatorandAngleValidatorrejectedNoneinside lists. So a figure with NaN in a list for a property that accepts NaN, such asmarker.color=[0, np.nan]with a colorscale,marker.angleor a baroffset, could be written withto_jsonbut not loaded again. As suggested in the issue, these validators now accept and keepNoneelements inside arrays. plotly.js already receivesnullfor these values today, since that is whatto_jsonsends, so what gets drawn doesn't change.Demo
Testing strategy
New validator tests check that
Noneelements are accepted and kept in lists for all three validators (and in object arrays for colors), with and without min/max or a colorscale. They also check that an invalid element next to aNoneis still reported, without theNone.test_from_json_nan_in_arraysround-trips a scattermarker.colorandmarker.angleand a baroffsetcontaining NaN. The new tests fail onmainand pass with this change.Locally (Windows, Python 3.12) I ran
tests/test_core,tests/test_io,tests/test_plotly_utilsandtests/test_optional. The same 53 tests fail onmainand on this branch in this environment, mostly because optional packages such as statsmodels aren't installed, plus Windows file-encoding errors in the offline HTML tests. Nothing else fails.ruff format --check .passes.Additional information (optional)
main, because they are serialized as typed arrays (bdata). Only lists and tuples hit this.marker.size=[1, None]ortextfont.color=["red", None]are now accepted, where they used to raise. NaN in the arrays of bounded properties such asmarker.sizeandmarker.opacityis still rejected when the figure is built (test_rejection_aok_min_max), so those never reachto_jsonwith a NaN. This PR leaves that as it is.Nonemeans the property is unset.IntegerValidatoris also unchanged, since its lists can't hold NaN in the first place.Guidelines