# Fix "'DataFrame' object has no attribute 'as_matrix'" after upgrading pandas

Yes. An agent finds every as_matrix call, replaces each with to_numpy, adds a test for the function that had none, and runs the suite on the pandas you install.

[Run this on Rush](https://cloud.getrush.ai/run/fix-dataframe-as-matrix-attribute-error/pandas/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the call sites before the dependency. In a research codebase like johnmartinsson/blood-glucose-prediction, `requirements.txt` pins `pandas==0.23.1`, `numpy==1.14.5` and `tensorflow==1.8.0`, and `as_matrix` appears exactly once: `utils.py` line 7, `sequence = df[column].as_matrix()` inside `dataframe_to_supervised`, which walks each column of a frame and hands the array to `sequence_to_supervised`. The method is called on a Series there, so the message a user sees is `AttributeError: 'Series' object has no attribute 'as_matrix'`, not the DataFrame wording in the search box; the agent names both in the pull request.

Then it traces who calls the function. `datasets/ohio.py`, the loader the README's `./run.py --file experiments/example.yaml -m train` goes through, already uses `df_glucose_level.values` at line 63 and calls `sequence_to_supervised` directly, and `datasets/normal_experiment.py` builds a numpy sequence with no frame at all. Nothing in the repository calls `dataframe_to_supervised`; it is library code waiting for a caller, and `test.py` covers `sequence_to_supervised` and `sequence_to_supervised_all` (two `unittest` cases) but not the function with the broken line. So the error is real for anyone who imports `utils` and uses that helper, and invisible to the training path.

The fix is `df[column].to_numpy()`. The agent prefers it to `.values` because pandas' own 0.23.0 note said "DataFrame.as_matrix is deprecated. Use DataFrame.values instead", and 1.0.0 then removed `DataFrame.as_matrix` and `Series.as_matrix` together, so the pinned release was already the last one to accept the call. It adds a third case to `test.py` that builds a two-column frame, calls `dataframe_to_supervised` with a short window, and checks the shapes that come back, then runs `python -m unittest test` on a current pandas and numpy: the two existing cases pass as they do today, and the new one fails on the old line and passes on the new one.

It reports the environment honestly. The pinned set cannot be installed on a current interpreter: pandas 0.23.1's metadata declares `pytz (>=2011k)`, which a current resolver refuses as not a valid version, so the agent installs current pandas and numpy for the test run and says so. It does not touch TensorFlow, the model code or the pins, and lists them as a separate decision.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Our Python code fails with \"'DataFrame' object has no attribute 'as_matrix'\" on a current pandas. Find every as_matrix call, say whether each is on a DataFrame or a Series and who calls the function it sits in, and replace each with to_numpy(). Where the function has no test, add one that exercises it. Run the existing test file before and after on the pandas version that actually installs, and open a pull request that quotes the error, names the pandas release that removed the method, and says which pinned requirements could not be installed and why.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **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.
2. **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.
3. **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 with two files changed: `utils.py` line 7 moves from `as_matrix()` to `to_numpy()`, and `test.py` gains a case for `dataframe_to_supervised`. The description quotes the Series and DataFrame forms of the error, cites the 0.23.0 deprecation and the 1.0.0 removal, shows `python -m unittest test` output on the versions it ran, and explains why the pinned set was not installed.

A reviewer checks that the new test actually calls the changed line, that the training loader in `datasets/ohio.py` was read and left alone because it never used the method, and decides separately whether to move the pandas and numpy pins now that the code no longer depends on a removed API.

## Run it on every Dependabot pull request that bumps pandas

The break lands with the bump, so the trigger is the pull request that moves pandas past 1.0. An automation with a `github` trigger on `pull_request.opened` and `pull_request.synchronize` runs this prompt on each one, with the event appended after the prompt, and pushes the `to_numpy` change and its test onto the bump's branch when the suite fails on `as_matrix`.

For many research repositories that still pin a pre-1.0 pandas, your server sends this request once per repository, each with its own UUID as `request_id` so a retry returns the run already started, and reads each `run.completed` webhook; a key starts at most `max_concurrent` runs at once and queues the rest.

## Why run it on Rush?

A one-word API removal hides in code that nothing exercises: here the broken line sits in a helper with no caller and no test, so a green training run proves nothing about it. In a Rush sandbox the agent installs the current library, writes the missing test, and shows it failing on the old line and passing on the new one, with the command output kept in the run.

Old scientific pins are their own trap: the agent finds that the 2018 pandas cannot even be resolved on a current interpreter and says exactly why, instead of silently testing on whatever happened to be installed. The reviewer gets a small diff, a test that guards it, and a clear statement of what environment the proof came from.

## Frequently asked questions

### Should it be .values or .to_numpy()?

Either removes the error. pandas' own 0.23.0 deprecation note pointed to `.values`; `.to_numpy()` is the method pandas added later as the explicit way to get an ndarray, and the agent uses it so the intent is visible at the call site. If your codebase standardises on `.values`, say so in the prompt.

### The error says 'Series', not 'DataFrame'. Is it the same problem?

Yes. `as_matrix` existed on both and 1.0.0 removed both. `df[column]` is a Series, so a call through a column shows the Series wording; the fix is the same method on either object.

### Why not just pin pandas below 1.0?

Because the pin that is already there cannot be installed on a current Python: its metadata names a pytz version a current resolver refuses. The agent fixes the code so it works on any pandas and leaves the question of which versions to pin to you, with the facts it found.

### Will it change the TensorFlow or model code?

No. The agent reads `run.py` and the dataset loaders to find out who calls the broken function, finds that the training path never does, and changes only the line with `as_matrix` and the test file.

## More pandas jobs

- [Fix "AttributeError: 'DataFrame' object has no attribute 'iteritems'" in pandas 2](https://getrush.ai/run/fix-dataframe-iteritems-attribute-error/pandas/)
- [Fix "AttributeError: 'DataFrame' object has no attribute 'ix'" in an Old pandas Script](https://getrush.ai/run/fix-dataframe-ix-attribute-error/pandas/)
- [Fix the delim_whitespace Keyword in pd.read_csv Is Deprecated Warning](https://getrush.ai/run/fix-delim-whitespace-keyword-is-deprecated-warning/pandas/)

## 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](https://getrush.ai/run/fix-debian-buster-release-file-missing/docker/)
- [Fix "MovedIn20Warning: The declarative_base() function is now available as sqlalchemy.orm.declarative_base()"](https://getrush.ai/run/fix-declarative-base-movedin20warning/sqlalchemy/)
- [Fix "options has an unknown property 'contentBase'" in webpack-dev-server](https://getrush.ai/run/fix-dev-server-unknown-property-contentbase/webpack-dev-server/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
