projects/guix·blob java-team · refs

48 lines · 2.4 KiB

1From f4e59d5a12d10b87d55f91e195ec4b8064fa66ca Mon Sep 17 00:00:00 2001
2From: goosfrabba <[email protected]>
3Date: Mon, 6 Jul 2026 10:58:21 -0700
4Subject: [PATCH] Fix DataFrame.applymap deprecation on pandas >= 2.1 without
5 dropping pandas < 2.1
6
7pandas >= 2.1 deprecates DataFrame.applymap in favour of DataFrame.map, so parallel_applymap
8raises a FutureWarning (#258). ApplyMap.work now uses DataFrame.map when the installed pandas
9provides it and falls back to applymap otherwise, fixing the deprecation without dropping
10pandas < 2.1 or bumping the minimum Python version (the concern raised on #259). The reference
11computation in test_dataframe_applymap uses the same capability check so it stays warning-free.
12---
13 pandarallel/data_types/dataframe.py | 6 ++++++
14 tests/test_pandarallel.py | 4 +++-
15 2 files changed, 9 insertions(+), 1 deletion(-)
16
17diff --git a/pandarallel/data_types/dataframe.py b/pandarallel/data_types/dataframe.py
18index 29c7e50..e1bc627 100644
19--- a/pandarallel/data_types/dataframe.py
20+++ b/pandarallel/data_types/dataframe.py
21@@ -66,6 +66,12 @@ def work(
22 user_defined_function_kwargs: Dict[str, Any],
23 extra: Dict[str, Any],
24 ) -> pd.DataFrame:
25+ # pandas >= 2.1 deprecates DataFrame.applymap in favour of DataFrame.map (added in 2.1);
26+ # older pandas only has applymap. Use whichever this pandas provides, so elementwise
27+ # apply keeps working and no longer raises the FutureWarning reported in #258, without
28+ # dropping support for pandas < 2.1.
29+ if hasattr(data, "map"):
30+ return data.map(user_defined_function)
31 return data.applymap(user_defined_function)
32
33 @staticmethod
34diff --git a/tests/test_pandarallel.py b/tests/test_pandarallel.py
35index 0f91c32..567c7d5 100644
36--- a/tests/test_pandarallel.py
37+++ b/tests/test_pandarallel.py
38@@ -232,7 +232,9 @@ def test_dataframe_applymap(pandarallel_init, func_dataframe_applymap, df_size):
39 )
40 df.index = [item / 10 for item in df.index]
41
42- res = df.applymap(func_dataframe_applymap)
43+ # pandas >= 2.1 renamed DataFrame.applymap to DataFrame.map; use whichever this pandas
44+ # provides so the reference computation stays warning-free across versions.
45+ res = (df.map if hasattr(df, "map") else df.applymap)(func_dataframe_applymap)
46 res_parallel = df.parallel_applymap(func_dataframe_applymap)
47 assert res.equals(res_parallel)
48