mirror of
https://codeberg.org/guix/guix.git
synced 2026-09-06 05:41:48 +00:00
* gnu/packages/patches/python-pandarallel-fix-df-applymap.patch: Add
patch.
* gnu/packages/patches/python-pandarallel-fix-parallel_apply.patch:
Likewise.
* gnu/local.mk (dist_patch_DATA): Record patches.
* gnu/packages/python-science.scm (python-pandarallel)
[source]{patches}: Record them.
Signed-off-by: Andreas Enge <andreas@enge.fr>
49 lines
2.4 KiB
Diff
49 lines
2.4 KiB
Diff
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)
|
|
|