Repository navigation
Accept a pandas Series with labels as a location - #2327
Open
nk-batman21 wants to merge 1 commit into
Open
nk-batman21 wants to merge 1 commit into
nk-batman21 wants to merge 1 commit into
Conversation
validate_location read location[0] and location[1]. On a Series with a string index, such as df[["lat", "lon"]].mean() or a DataFrame row, that relied on the positional fallback of Series.__getitem__, which pandas 2 deprecated and pandas 3 removed. Convert a Series to a list first, the same way numpy arrays and DataFrames are handled.
This branch was successfully 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.
With pandas 3, a pandas Series that has labels is no longer accepted as a location. That is the usual shape when building a map from a DataFrame:
Both lines raise
TypeError: Location should support indexing, like a list or a tuple does, ..., and so doPolyLineorPolygonbuilt from DataFrame rows.validate_locationreadslocation[0]andlocation[1], which on a Series with a string index only worked through the positional fallback ofSeries.__getitem__. pandas 2 printed a FutureWarning for that on every call, and pandas 3 removed it, so the lookup now raises KeyError.This converts a Series to a list before validating it, like numpy arrays and DataFrames already are.
test_validate_locationalready acceptspd.Series([5, 3]); I added the same values with alat/lonindex.Ran:
python -m pytest --ignore=tests/selenium --ignore=tests/playwright --ignore=tests/snapshots --ignore=tests/test_repr.pyon Python 3.14 with pandas 3.1.0 and on Python 3.10 with pandas 2.3.3. The new case fails before the change on pandas 3 and passes after it on both, also with-W error::FutureWarningon pandas 2.Checked: ruff, black and
mypy folium.