What the agent does
The agent reads the script that raised the error and the file that installs its dependencies. In DestructHub/ProjectEuler, a repository of solutions in many languages, stats.py builds a table of how many solutions each problem has per language, and requirements.txt lists pandas, numpy and sympy with no versions. A clean install today resolves pandas 3.1.1 and NumPy 2.4.6. The script's count_solutions function, line 511, is df_ = df.applymap(lambda x: len(x) if x is not np.NAN else 0), and blame_solutions on lines 640 to 643 calls applymap again with np.NAN three times. Running python stats.py -c -a, -l -c or -m -a ends on the error in the title, and so does every option that reaches those two functions.
Then it pins the boundary. On pandas 2.2.3 the same call works and prints FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead. DataFrame.map exists from pandas 2.1.0 and not in 2.0.3, so the replacement has a floor of its own, and the agent writes pandas>=2.1 into requirements.txt so the fix cannot be installed beside a release that lacks it. The same release of pandas 3 also removed Styler.applymap, whose replacement is Styler.map, so the agent searches for .style.applymap as well as .applymap.
The lambda hides a second break. np.NAN was removed in NumPy 2.0 along with the other capitalised aliases, so once applymap is renamed the next run fails on AttributeError: module 'numpy' has no attribute 'NAN'. The agent changes those four uses to np.nan, which has been the spelling all along, and leaves the identity comparison x is not np.nan as it is, because the script fills the frame with that exact object and changing the comparison would change what counts as empty.
Proof is the script's own output. The agent runs stats.py -c -a on the branch and, in a second environment, the original script on pandas 2.2.3 and NumPy 1.26.4, and compares the two tables after sorting their rows, since the script lists problems in the order it walks the directories. In the sandbox both runs produce the same eighty-four problem rows and twenty-nine columns with the same counts in every cell. On a current Python the first line to fail is a different one, from distutils.spawn import find_executable on line 13, since distutils is gone from Python 3.12; the agent notes it and the shutil.which replacement in the pull request without widening the change.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "This project fails with \"AttributeError: 'DataFrame' object has no attribute 'applymap'\". Find every applymap call on a DataFrame or a Styler and list each with file and line. Read the dependency files and say which pandas and numpy a clean install resolves. Reproduce the error on the newest pandas, then show the FutureWarning the last 2.x release printed for the same line, and find by installing them the first pandas release that has DataFrame.map. Replace each call with .map, keeping the function and any subset or keyword arguments the same, and set the floor you found wherever pandas is declared. Run the script again and fix whatever fails next in the same lines, such as removed numpy aliases, each with the release that removed it. Prove the output is unchanged: run the script on the branch and the original script on the last pandas and numpy that accepted it, and compare the results, sorting rows if the script's order is not stable. Open a pull request with the version findings and the comparison.",
"resources": [
{
"url": "https://github.com/your-org/your-app"
}
]
}- Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
- Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
- Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.
What comes back
A pull request that changes two applymap calls and four np.NAN spellings in stats.py, and adds a lower bound for pandas in requirements.txt. The description quotes the error, the FutureWarning from pandas 2.2 and the NumPy error that appeared after the rename, names the release each replacement needs, and shows the sorted output of the old and new runs matching line for line, with the row and column counts.
A reviewer checks that the comparison was run on the same checkout, so the solution counts could not differ for another reason, and that the floor added to the dependency file matches the method the code now calls. If the repository builds a graph or a README section from this table, the reviewer regenerates it once on the branch and confirms it is identical.
The agent does not touch distutils, the file's other time bomb, beyond naming it and its replacement, so the pull request stays one change with one proof.
Run it on every Dependabot or Renovate pull request on pandas
A major pandas release reaches most projects as a bot's pull request, and the failing job on that pull request is the alert. An automation with a github trigger on pull requests starts one run per such event, with the event appended to the prompt, and its prompt tells the agent to act only when the bump is pandas or numpy and the job log contains has no attribute. The automation's own runs-per-hour cap keeps a burst of bot pull requests from starting more runs than you want.
For a repository with no bot, a weekly scheduled run that upgrades pandas in a fresh environment, runs the scripts named in the prompt and opens a pull request only when one of them fails catches the same break on your schedule rather than a user's.
The use case this job follows, with its automation and trigger: Fix a bug from an alert.
Why run it on Rush?
The rename is one word, but proving the numbers are unchanged needs two environments, the old pandas with the old NumPy beside the new, and a run of the real script in each. In a Rush sandbox the agent makes both, runs the script on the project's actual data, and keeps every command and both outputs in the session, so the comparison in the pull request can be checked rather than believed.
The second error only shows up after the first is fixed, and the third only on a newer interpreter. A run that reproduces, fixes and runs again, as many times as it takes, finds that chain in one pass, and reports the pieces it chose not to change along with the reason.
Frequently asked questions
What replaces DataFrame.applymap?
DataFrame.map, added in pandas 2.1.0 with the same signature: a function applied to every element, plus na_action and keyword arguments passed through. Styler.applymap became Styler.map in the same release, and pandas 3 removed both old names.
Why does the run fail again right after the rename?
Because the function inside the call used np.NAN, which NumPy 2.0 removed along with np.NaN, np.Inf and np.infty. The spelling that works on every release is np.nan. The agent fixes those in the same lines and names the NumPy release for each.
Will the output change?
It should not, and the pull request shows that it did not: the same script run on the old pandas and on the branch produces the same table, compared after sorting when the script's own row order depends on the filesystem.
Should I pin pandas below 3 instead?
It works as a stopgap and is the right call for a dependency you cannot patch. For your own code the rename is small and DataFrame.map exists from pandas 2.1, so the fix does not force the newest pandas on anyone.
More pandas jobs
More jobs like this: Fix a bug from an alert
- Fix "The repository 'http://deb.debian.org/debian buster Release' does not have a Release file" in a Docker build (Docker)
- Fix "MovedIn20Warning: The declarative_base() function is now available as sqlalchemy.orm.declarative_base()" (SQLAlchemy)
- Fix "options has an unknown property 'contentBase'" in webpack-dev-server (webpack-dev-server)