Skip to content

Fix DataFrame.applymap deprecation on pandas >= 2.1 (keeps pandas < 2.1 working) - #280

Open
goosfrabba wants to merge 1 commit into
nalepae:masterfrom
goosfrabba:fix-applymap-deprecation-pandas-2.1
Open

Fix DataFrame.applymap deprecation on pandas >= 2.1 (keeps pandas < 2.1 working)#280
goosfrabba wants to merge 1 commit into
nalepae:masterfrom
goosfrabba:fix-applymap-deprecation-pandas-2.1

Conversation

@goosfrabba

Copy link
Copy Markdown

Fixes #258.

On pandas >= 2.1, DataFrame.applymap is deprecated in favour of DataFrame.map, so parallel_applymap currently raises FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead (from pandarallel/data_types/dataframe.py).

This makes the elementwise apply version-aware: it uses DataFrame.map when the installed pandas provides it (>= 2.1) and falls back to DataFrame.applymap otherwise. That resolves the deprecation without dropping support for pandas < 2.1 and without raising the minimum Python version, addressing the concern raised on #259 (a hard applymap -> map swap).

  • pandarallel/data_types/dataframe.py: ApplyMap.work picks map/applymap by capability.
  • tests/test_pandarallel.py: the reference in test_dataframe_applymap uses the same capability check so it stays warning-free across pandas versions.

A sensible follow-up is extending the CI matrix to pandas 2.1/2.2 and Python 3.11-3.13 so this class of regression is caught automatically.

…pandas < 2.1

pandas >= 2.1 deprecates DataFrame.applymap in favour of DataFrame.map, so parallel_applymap
raises a FutureWarning (nalepae#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 nalepae#259). The reference
computation in test_dataframe_applymap uses the same capability check so it stays warning-free.
@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.55%. Comparing base (261a652) to head (f4e59d5).

Files with missing lines Patch % Lines
pandarallel/data_types/dataframe.py 0.00% 2 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (261a652) and HEAD (f4e59d5). Click for more details.

HEAD has 58 uploads less than BASE
Flag BASE (261a652) HEAD (f4e59d5)
63 5
Additional details and impacted files
@@             Coverage Diff             @@
##           master     #280       +/-   ##
===========================================
- Coverage   91.28%   79.55%   -11.73%     
===========================================
  Files          12       12               
  Lines         585      587        +2     
===========================================
- Hits          534      467       -67     
- Misses         51      120       +69     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@goosfrabba

Copy link
Copy Markdown
Author

Heads up on the red CI: the macOS failures are environment rot in the old-pandas matrix, not related to this patch — pandas 1.x wheels hitting the numpy 2.x ABI break (numpy.dtype size changed), and pandas source builds failing on newer setuptools (No module named 'pkg_resources'). Pinning numpy<2 for the pandas<2 jobs (and setuptools<81 for the 3.9 source builds) should green them. Happy to add that to this PR or a separate one if useful.

@LalwaniPalash

Copy link
Copy Markdown

Some test evidence in support of this, from running the suite on pandas 3.0.3 / Python 3.14.6.

Worth flagging that on pandas 3.0 this is no longer a deprecation — DataFrame.applymap has
been removed outright:

AttributeError: 'DataFrame' object has no attribute 'applymap'

So parallel_applymap currently raises for every caller on pandas 3.x, and
test_dataframe_applymap accounts for 16 of the 24 failures in the suite. The hasattr(data, "map")
guard here handles that correctly — DataFrame.map exists from pandas 2.1 onward, so the fallback
still covers older versions.

The other 8 failures are unrelated (grouping columns are no longer passed to apply on pandas 3.0);
I've opened #282 for those. Combining the two branches locally:

failed passed
master 24 193
master + #282 16 201
master + #280 8 209
master + both 0 217

One caveat on CI: the workflow matrix targets ubuntu-20.04, which GitHub has retired, so those
jobs are cancelled before they run — that's why this PR shows red rather than anything to do with
the change itself. The matrix also tops out at pandas 2.0, so it wouldn't exercise this fix either
way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DataFrame.applymap has been deprecated.

2 participants