zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import numpy as np
import pytest
 
from pandas import DataFrame
import pandas._testing as tm
 
 
class TestSwapAxes:
    def test_swapaxes(self):
        df = DataFrame(np.random.randn(10, 5))
        tm.assert_frame_equal(df.T, df.swapaxes(0, 1))
        tm.assert_frame_equal(df.T, df.swapaxes(1, 0))
 
    def test_swapaxes_noop(self):
        df = DataFrame(np.random.randn(10, 5))
        tm.assert_frame_equal(df, df.swapaxes(0, 0))
 
    def test_swapaxes_invalid_axis(self):
        df = DataFrame(np.random.randn(10, 5))
        msg = "No axis named 2 for object type DataFrame"
        with pytest.raises(ValueError, match=msg):
            df.swapaxes(2, 5)
 
    def test_round_empty_not_input(self):
        # GH#51032
        df = DataFrame({"a": [1, 2]})
        result = df.swapaxes("index", "index")
        tm.assert_frame_equal(df, result)
        assert df is not result