Repository navigation
Conversation
mercator_transform always returned a float64 array, so a uint8 image passed to ImageOverlay(mercator_project=True) reached write_png as float data and had every channel rescaled to its maximum. A uniform (100, 50, 200, 255) image came out white. Round and cast the result back to the input's integer dtype.
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
mercator_transformalways returns a float64 array. When a uint8 image is passed toImageOverlay(..., mercator_project=True),write_pngthen sees float data and rescales every channel to its own maximum, so the colours change. A uniform(100, 50, 200, 255)image comes out white:Changes
If the input has an integer dtype, round the interpolated result and cast it back to that dtype. Float input is unchanged, so the existing
test_image_overlayURL stays the same.Two regression tests were added:
mercator_transformkeeps uint8 data unchanged for a uniform image, andImageOverlayproduces the same URL for that image with and withoutmercator_project.Validation
folium/utilities.pyreverted), both new tests fail:assert dtype('float64') == <class 'numpy.uint8'>and a URL mismatch. With the fix both pass.python -m pytest tests --ignore=tests/selenium --ignore=tests/snapshots: 397 passed, 3 failed. The 3 failures are intests/test_repr.py(cannot import name 'webdriver' from 'selenium', since selenium isn't installed) and fail the same way onmain.ruff check folium tests(0.16.10),black --check folium tests(26.10.0),codespellon the changed files, andmypy foliumpass.