summaryrefslogtreecommitdiff
path: root/gnu/packages/patches/python-pandarallel-fix-df-applymap.patch
blob: 8aef98a03fcf95a7667e12690bf79a389c5038e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
From f4e59d5a12d10b87d55f91e195ec4b8064fa66ca Mon Sep 17 00:00:00 2001
From: goosfrabba <16498111+goosfrabba@users.noreply.github.com>
Date: Mon, 6 Jul 2026 10:58:21 -0700
Subject: [PATCH] Fix DataFrame.applymap deprecation on pandas >= 2.1 without
 dropping pandas < 2.1

pandas >= 2.1 deprecates DataFrame.applymap in favour of DataFrame.map, so parallel_applymap
raises a FutureWarning (#258). ApplyMap.work now uses DataFrame.map when the installed pandas
provides it and falls back to applymap otherwise, fixing the deprecation without dropping
pandas < 2.1 or bumping the minimum Python version (the concern raised on #259). The reference
computation in test_dataframe_applymap uses the same capability check so it stays warning-free.
---
 pandarallel/data_types/dataframe.py | 6 ++++++
 tests/test_pandarallel.py           | 4 +++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/pandarallel/data_types/dataframe.py b/pandarallel/data_types/dataframe.py
index 29c7e50..e1bc627 100644
--- a/pandarallel/data_types/dataframe.py
+++ b/pandarallel/data_types/dataframe.py
@@ -66,6 +66,12 @@ def work(
             user_defined_function_kwargs: Dict[str, Any],
             extra: Dict[str, Any],
         ) -> pd.DataFrame:
+            # pandas >= 2.1 deprecates DataFrame.applymap in favour of DataFrame.map (added in 2.1);
+            # older pandas only has applymap. Use whichever this pandas provides, so elementwise
+            # apply keeps working and no longer raises the FutureWarning reported in #258, without
+            # dropping support for pandas < 2.1.
+            if hasattr(data, "map"):
+                return data.map(user_defined_function)
             return data.applymap(user_defined_function)
 
         @staticmethod
diff --git a/tests/test_pandarallel.py b/tests/test_pandarallel.py
index 0f91c32..567c7d5 100644
--- a/tests/test_pandarallel.py
+++ b/tests/test_pandarallel.py
@@ -232,7 +232,9 @@ def test_dataframe_applymap(pandarallel_init, func_dataframe_applymap, df_size):
     )
     df.index = [item / 10 for item in df.index]
 
-    res = df.applymap(func_dataframe_applymap)
+    # pandas >= 2.1 renamed DataFrame.applymap to DataFrame.map; use whichever this pandas
+    # provides so the reference computation stays warning-free across versions.
+    res = (df.map if hasattr(df, "map") else df.applymap)(func_dataframe_applymap)
     res_parallel = df.parallel_applymap(func_dataframe_applymap)
     assert res.equals(res_parallel)