From fe21ea9c7b770623e281c0049d9cc3513823281e Mon Sep 17 00:00:00 2001 From: nk-batman21 Date: Mon, 2 Nov 2026 04:18:59 +0700 Subject: [PATCH] Accept a pandas Series with labels as a location 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. --- folium/utilities.py | 2 ++ tests/test_utilities.py | 1 + 2 files changed, 3 insertions(+) diff --git a/folium/utilities.py b/folium/utilities.py index e9807ad91d..6e6c750633 100644 --- a/folium/utilities.py +++ b/folium/utilities.py @@ -73,6 +73,8 @@ def validate_location(location: Sequence[float]) -> list[float]: pd is not None and isinstance(location, pd.DataFrame) ): location = np.squeeze(location).tolist() + elif pd is not None and isinstance(location, pd.Series): + location = location.tolist() if not hasattr(location, "__len__"): raise TypeError( "Location should be a sized variable, " diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 26d346ca39..854f50b047 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -29,6 +29,7 @@ np.array([5, 3]), np.array([[5, 3]]), pd.Series([5, 3]), + pd.Series([5, 3], index=["lat", "lon"]), pd.DataFrame([5, 3]), pd.DataFrame([[5, 3]]), ("5.0", "3.0"),