Skip to content

fix(storage): replace removed DataFrame.applymap in LazyFileStorage - #562

Merged
SunnyHaze merged 1 commit into
OpenDCAI:mainfrom
cyberspace-cs:fix/pandas3-applymap
Oct 19, 2026
Merged

SunnyHaze merged 1 commit into
OpenDCAI:mainfrom
cyberspace-cs:fix/pandas3-applymap

Conversation

@cyberspace-cs

Copy link
Copy Markdown
Contributor

What

LazyFileStorage.write calls DataFrame.applymap, which was removed in pandas 3.0. Any operator that writes a DataFrame through LazyFileStorage now fails with:

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

Why this is live, not a deprecation warning

requirements.txt does not constrain pandas, so a fresh install today resolves to 3.x and hits this on the first write. The bundled example pipelines never reach it because they write through FileStorage, not LazyFileStorage — which is exactly why the failure is invisible until someone uses the lazy path.

This is the site #371 missed

#371 ("switch df.applymap() to df.map") changed one line in this file — FileStorage.write — and left LazyFileStorage.write on the removed API. The two classes are siblings with the same shape:

class method on main
FileStorage write data.map(clean_surrogates) — fixed by #371
LazyFileStorage write data.applymap(clean_surrogates) — this PR

Fix

DataFrame.map is the replacement and has existed since pandas 2.1. Keep a fallback so environments still on an older pandas are unaffected:

if hasattr(data, "map"):
    dataframe = data.map(clean_surrogates)
else:
    dataframe = data.applymap(clean_surrogates)

Evidence

Bidirectional check against 05a7d9e (current main), Python 3.13.14 / pandas 3.0.6:

# test only, fix reverted
$ pytest test/cpu_only/test_lazy_storage_dataframe_write.py
1 failed, 1 passed
E   AttributeError: 'DataFrame' object has no attribute 'applymap'

# with fix
$ pytest test/cpu_only/test_lazy_storage_dataframe_write.py
2 passed

The second test does not just assert "no exception": it checks that surrogate cleaning still happens and that the written file round-trips, so the fix cannot silently change behaviour.

grep -rn applymap dataflow/ now returns only the fallback branch above.

Happy to drop the fallback if you consider pandas < 2.1 out of scope.

DataFrame.applymap was removed in pandas 3.0 and requirements.txt does not
pin pandas, so a fresh install resolves to pandas 3.x and any operator that
writes a DataFrame through LazyFileStorage fails with:

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

DataFrame.map is the replacement and exists since pandas 2.1; keep a fallback
for environments still on an older pandas. FileStorage.write in the same file
already uses data.map, so this brings LazyFileStorage in line with its sibling.
@SunnyHaze

Copy link
Copy Markdown
Collaborator

LGTM, thanks. PR will be merged after CI check.

@SunnyHaze
SunnyHaze merged commit 2ed3c30 into OpenDCAI:main Oct 19, 2026
6 checks passed
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.

2 participants