test_swapaxes.py 885 B

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