Repository navigation
Fix image_to_url crash on non-ndarray array-like images - #2344
Open
kavyalavti wants to merge 1 commit into
Open
kavyalavti wants to merge 1 commit into
kavyalavti wants to merge 1 commit into
Conversation
image_to_url only passed numpy.ndarray instances to write_png. Other array-like inputs, such as nested lists, fell through to the JSON branch and crashed with AttributeError. Send every non-string image to write_png, which already accepts list-like data. Fixes python-visualization#2343 Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Problem
ImageOverlayandfolium.utilities.image_to_urldocumentimageas accepting an array-like object, but only realnumpy.ndarrayinstances work. A nested list or tuple crashes withAttributeError: 'list' object has no attribute 'replace'.Reproduce
Fix
image_to_urlchose the PNG branch with"ndarray" in image.__class__.__name__, so every other non-string input fell through to the JSON round-trip branch, which returns the list unchanged before.replaceis called on it. The PNG branch now handles every non-string input.branca.utilities.write_pngalready accepts list-like data. Strings still take the same paths as before: file paths are embedded, and URLs are passed through.Tests
test_image_to_url_array_like, which checks that lists and tuples (mono and RGB) produce the same data URL as the equivalentnp.array. It fails onmainand passes with the fix.test_image_to_url_urlto cover URL pass-through.pytest tests --ignore=tests/selenium --ignore=tests/snapshots: 400 passed. The 3 failures intests/test_repr.pyalso fail onmainlocally because they need a Chrome webdriver.AI disclosure: this change was prepared with the help of Claude Code (Anthropic). I reviewed the diff and test results.
Fixes #2343
🤖 Generated with Claude Code