What the agent does
pandas 2.0 removed iteritems from both DataFrame and Series. The method had been an alias of items for years, pandas 1.5 warned on every call (FutureWarning: iteritems is deprecated and will be removed in a future version. Use .items instead.), and from 2.0.0 the call raises AttributeError: 'DataFrame' object has no attribute 'iteritems', or the same message with 'Series'. Code that never pinned pandas meets this on the first fresh install after the release, often years after the last commit.
brentp/combat.py, a Python port of the ComBat batch-correction method used in genomics, is a clear case. requirements.txt holds two unpinned lines, pandas and patsy. Line 80 of combat.py builds the list of intercept columns to drop with ((model == 1).all()).iteritems(), a call on a Series. .travis.yml tests Python 2.6 to 3.4 and its script is python combat.py followed by python test.py. On Python 3.12 a fresh install resolves to pandas 3.1.1, numpy 2.5.4 and patsy 1.0.3, and python combat.py stops at line 80, called from line 222, with AttributeError: 'Series' object has no attribute 'iteritems'.
The agent reproduces that first, then searches the whole repository for iteritems(, including notebooks, and decides for each hit what the receiver is. A pandas object gets .items(), which returns the same pairs: column label and Series for a frame, index label and value for a series. A plain dict in code that still supports Python 2 is a different problem and is reported, not silently rewritten. items exists on every pandas version this code could be installed with, so the change needs no version floor in requirements.txt and no compatibility branch.
Then it runs what the repository offers as a check. Here that is a strong one: combat.py writes its corrected matrix to py-batch.txt, and test.py asserts that it differs from r-batch.txt, the output of the original R implementation committed in the repository, by less than 1e-4. With the one call renamed, the script completes on pandas 3.1.1 and that assertion holds. An old script on a new pandas often has more than one removed call in its path, so the agent keeps running until the entry point finishes and lists each further error it had to fix, or states that there were none.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "This repository fails with AttributeError: 'DataFrame' object has no attribute 'iteritems' (or the same error for 'Series') after pandas was upgraded. Read the dependency files (requirements.txt, setup.py, pyproject.toml, environment.yml) and report how pandas and numpy are pinned, and read the CI configuration to see which Python versions and commands it runs. Create a clean virtual environment on the newest Python the project claims to support, install the dependencies as a new user would, and report the versions that were resolved. Run the entry point or the test suite and save the first traceback. Search every .py and .ipynb file for iteritems( and list each call with its file and line and whether the receiver is a pandas DataFrame, a pandas Series, or a dict. Replace the pandas calls with .items(). Do not add a pandas version pin to hide the error and do not add try/except or hasattr branches. Report dict.iteritems calls separately and change them only if the project no longer supports Python 2. Run the entry point again and keep fixing errors caused by removed pandas or numpy APIs until it completes, listing each one with the release that removed it. If the repository has reference output or a regression test, run it and report the result; if it does not, run the script on the last pandas 1.x release and on the current release and compare the outputs numerically. Open a pull request with the list of changed calls, the resolved versions, 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 whose diff is small and literal: each iteritems() on a pandas object becomes items(). In a single-file library like the one above that can be one line. The description lists every call that was found, the versions a clean install resolved to, the traceback before the change and the result of the repository's own check after it.
What a reviewer looks at is the evidence that the numbers did not move. A rename of an alias cannot change results by itself, but the pull request claims more than the rename: that the code runs on a pandas two major versions newer than the one it was written for. The description therefore states which comparison was made, against committed reference output or between two pandas versions, and the largest difference found.
If the entry point needed further changes to finish, each is a separate commit named after the API that was removed, so a reviewer can accept the rename and discuss the rest. Calls on a dict that the agent left alone are listed with the reason.
Run it on every Monday morning
A repository with unpinned dependencies changes without a commit, so there is no push to hang a check on. Give the Project an automation with a schedule trigger, for example the cron expression 0 7 * * 1 in your timezone, and a prompt that tells the agent to install the dependencies fresh, run the entry point, and open a pull request only when it fails on an API that a new release removed. On a week when nothing broke, the run ends with a one-line answer and no pull request.
For a group of analysis repositories that share this pattern, start the request above once per repository from a script with an API key. Each run resolves its own versions in its own sandbox, and runs past the key's max_concurrent limit are accepted and wait as queued.
The use case this job follows, with its automation and trigger: Fix a bug from an alert.
Why run it on Rush?
The edit takes a minute. The question worth a run is whether the script still produces the same numbers on a pandas and a numpy that are years newer than the ones it was tested with, and answering it takes two clean environments, a full run in each, and a comparison. An agent in a sandbox builds both, runs the real entry point on real input files, and leaves the commands and their output in the session, so the pull request arrives with the comparison already made.
It also starts from the state your users are in. A developer's environment usually holds whichever pandas was current when the project was last touched, and the error never appears there. A sandbox has no history: the install resolves what a new clone would get today, which is the only environment where this bug exists.
Frequently asked questions
Is items() exactly the same as iteritems()?
For pandas objects, yes. iteritems was an alias kept for Python 2 habits, and both yield label and value pairs lazily. items has been available for many releases, so the replacement works on pandas 1.x and 2.x alike.
Can I pin pandas below 2.0 instead?
It works until something else in the environment requires pandas 2, or until you move to a Python version that old pandas releases publish no wheels for. Since the fix is a rename with no behaviour change, pinning mostly postpones it. The request above tells the agent not to pin.
The traceback says 'Series', not 'DataFrame'. Is it the same problem?
Yes. pandas 2.0.0 removed the method from both classes in the same release, and which name you see depends only on the object the call was made on. A search for iteritems( finds both kinds.
What about iteritems() on a dictionary?
That is Python 2 syntax, not pandas, and it fails on Python 3 with a similar message about 'dict'. The agent reports those calls separately. If the project has dropped Python 2 they become .items() too; if it still claims to support it, the agent says so and leaves the decision to you.
Will other pandas 2 removals be fixed in the same run?
Only the ones the entry point actually hits. The agent runs until the script completes and fixes each removed call on that path as its own commit, with the release that removed it. It does not rewrite code the run never reached.
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)