DEPR: Deprecate NDFrame.swapaxes
State: closed

- [x] xref #18262
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

``.swapaxes`` are not needed, now that ``Panel`` is being removed.

Labels:
name: Reshaping
description: Concat, Merge/Join, Stack/Unstack, Explode
name: Deprecate
description: Functionality to remove in pandas

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26654?src=pr&el=h1) Report
> Merging [#26654](https://codecov.io/gh/pandas-dev/pandas/pull/26654?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/01d97d48b08c546a46b91c27a5886f52b46f22c2?src=pr&el=desc) will **decrease** coverage by `50.06%`.
> The diff coverage is `0%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/26654/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/26654?src=pr&el=tree)

```diff
@@             Coverage Diff             @@
##           master   #26654       +/-   ##
===========================================
- Coverage   91.87%   41.81%   -50.07%     
===========================================
  Files         174      174               
  Lines       50683    50684        +1     
===========================================
- Hits        46567    21191    -25376     
- Misses       4116    29493    +25377
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `?` | |
| #single | `41.81% <0%> (-0.07%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26654?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/groupby/ops.py](https://codecov.io/gh/pandas-dev/pandas/pull/26654/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9vcHMucHk=) | `19.76% <0%> (-76.24%)` | :arrow_down: |
| [pandas/core/generic.py](https://codecov.io/gh/pandas-dev/pandas/pull/26654/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ2VuZXJpYy5weQ==) | `37.96% <0%> (-55.67%)` | :arrow_down: |
| [pandas/io/formats/latex.py](https://codecov.io/gh/pandas-dev/pandas/pull/26654/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvbGF0ZXgucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/io/sas/sas\_constants.py](https://codecov.io/gh/pandas-dev/pandas/pull/26654/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXNfY29uc3RhbnRzLnB5) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/core/groupby/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/26654/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9jYXRlZ29yaWNhbC5weQ==) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/tseries/plotting.py](https://codecov.io/gh/pandas-dev/pandas/pull/26654/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvcGxvdHRpbmcucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/tseries/converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/26654/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvY29udmVydGVyLnB5) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/io/formats/html.py](https://codecov.io/gh/pandas-dev/pandas/pull/26654/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvaHRtbC5weQ==) | `0% <0%> (-99.37%)` | :arrow_down: |
| [pandas/io/sas/sas7bdat.py](https://codecov.io/gh/pandas-dev/pandas/pull/26654/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXM3YmRhdC5weQ==) | `0% <0%> (-91.16%)` | :arrow_down: |
| [pandas/io/sas/sas\_xport.py](https://codecov.io/gh/pandas-dev/pandas/pull/26654/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXNfeHBvcnQucHk=) | `0% <0%> (-90.1%)` | :arrow_down: |
| ... and [130 more](https://codecov.io/gh/pandas-dev/pandas/pull/26654/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26654?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26654?src=pr&el=footer). Last update [01d97d4...676a2e4](https://codecov.io/gh/pandas-dev/pandas/pull/26654?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26654?src=pr&el=h1) Report
> Merging [#26654](https://codecov.io/gh/pandas-dev/pandas/pull/26654?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/1d7ad5fd7577f3da1c8eb19cf547f62d392405d0?src=pr&el=desc) will **increase** coverage by `50.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/26654/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/26654?src=pr&el=tree)

```diff
@@             Coverage Diff             @@
##           master   #26654       +/-   ##
===========================================
+ Coverage   41.84%   91.86%   +50.01%     
===========================================
  Files         174      174               
  Lines       50663    50664        +1     
===========================================
+ Hits        21201    46543    +25342     
+ Misses      29462     4121    -25341
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.4% <100%> (?)` | |
| #single | `41.75% <0%> (-0.1%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26654?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/internals/blocks.py](https://codecov.io/gh/pandas-dev/pandas/pull/26654/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW50ZXJuYWxzL2Jsb2Nrcy5weQ==) | `94.12% <ø> (+41.36%)` | :arrow_up: |
| [pandas/core/generic.py](https://codecov.io/gh/pandas-dev/pandas/pull/26654/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ2VuZXJpYy5weQ==) | `93.54% <100%> (+55.55%)` | :arrow_up: |
| [pandas/core/groupby/ops.py](https://codecov.io/gh/pandas-dev/pandas/pull/26654/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9vcHMucHk=) | `96% <100%> (+76.23%)` | :arrow_up: |
| [pandas/core/computation/pytables.py](https://codecov.io/gh/pandas-dev/pandas/pull/26654/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vcHl0YWJsZXMucHk=) | `90.24% <0%> (+0.3%)` | :arrow_up: |
| [pandas/io/pytables.py](https://codecov.io/gh/pandas-dev/pandas/pull/26654/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3B5dGFibGVzLnB5) | `90.29% <0%> (+0.96%)` | :arrow_up: |
| [pandas/core/panel.py](https://codecov.io/gh/pandas-dev/pandas/pull/26654/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcGFuZWwucHk=) | `17.61% <0%> (+1.68%)` | :arrow_up: |
| [pandas/util/\_test\_decorators.py](https://codecov.io/gh/pandas-dev/pandas/pull/26654/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvX3Rlc3RfZGVjb3JhdG9ycy5weQ==) | `93.22% <0%> (+5.08%)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/26654/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `78.94% <0%> (+5.26%)` | :arrow_up: |
| [pandas/\_config/localization.py](https://codecov.io/gh/pandas-dev/pandas/pull/26654/diff?src=pr&el=tree#diff-cGFuZGFzL19jb25maWcvbG9jYWxpemF0aW9uLnB5) | `86% <0%> (+6%)` | :arrow_up: |
| [pandas/core/config\_init.py](https://codecov.io/gh/pandas-dev/pandas/pull/26654/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29uZmlnX2luaXQucHk=) | `96.85% <0%> (+10.23%)` | :arrow_up: |
| ... and [131 more](https://codecov.io/gh/pandas-dev/pandas/pull/26654/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26654?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26654?src=pr&el=footer). Last update [1d7ad5f...518ef5d](https://codecov.io/gh/pandas-dev/pandas/pull/26654?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

This passes locally, but is somehow failing on numpy_dev. I'll see it I can figure it out.
> This passes locally, but is somehow failing on numpy_dev. I'll see it I can figure it out.

From the tracebacks on Azure, it might be from `np.swapaxes` which ends up calling the `swapaxes` method, raising the warning, and warnings from numpy are turned into errors on that build I think.

Not sure there is anything we can do about that .. (apart from actually implementing `__array_function__`)
> From the tracebacks on Azure, it might be from np.swapaxes which ends up calling the swapaxes method, raising the warning, and warnings from numpy are turned into errors on that build I think.

Thanks, that's something to investigate. Could be there's a ``np.swapaxes(df)`` that could be changed to ``np.swapaxes(df.values)`` somewhere?
>  Could be there's a np.swapaxes(df) that could be changed to np.swapaxes(df.values) somewhere?

I suppose it is actually numpy calling it. Basically, `np.swapaxes(obj, ..)` will check if `obj` has a `swapaxes` method. That also happens with `mean`, `sum`, etc, so I suppose that might be the case here as wel.
I'm taking this private for a while. I think ``np.swapaxes(df, 0, 1)`` should work on principle, and I'll see if I can get something to work.