code: def test_swaplevel(self):
      # MultiIndex with two levels
      arrays = [[1, 1, 2, 2], ["red", "blue", "red", "blue"]]
      pidx = pd.MultiIndex.from_arrays(
          arrays, names=("number", "color")
      )
      pser = pd.Series(["a", "b", "c", "d"], index=pidx)
      psser = ps.from_pandas(pser)
      self.assert_eq(pser.swaplevel(), psser.swaplevel())
      self.assert_eq(pser.swaplevel(0, 1), psser.swaplevel(0, 1))
      self.assert_eq(pser.swaplevel(1, 1), psser.swaplevel(1, 1))
      self.assert_eq(
          pser.swaplevel("number", "color"),
          psser.swaplevel("number", "color"),
      )
  
      # MultiIndex with more than two levels
      arrays = [
          [1, 1, 2, 2],
          ["red", "blue", "red", "blue"],
          ["l", "m", "s", "xs"],
      ]
      pidx = pd.MultiIndex.from_arrays(
          arrays, names=("number", "color", "size")
      )
      pser = pd.Series(["a", "b", "c", "d"], index=pidx)
      psser = ps.from_pandas(pser)
      self.assert_eq(pser.swaplevel(), psser.swaplevel())
      self.assert_eq(pser.swaplevel(0, 1), psser.swaplevel(0, 1))
      self.assert_eq(pser.swaplevel(0, 2), psser.swaplevel(0, 2))
      self.assert_eq(pser.swaplevel(1, 2), psser.swaplevel(1, 2))
      self.assert_eq(pser.swaplevel(1, 1), psser.swaplevel(1, 1))
      self.assert_eq(pser.swaplevel(-1, -2), psser.swaplevel(-1, -2))
      self.assert_eq(
          pser.swaplevel("number", "color"),
          psser.swaplevel("number", "color"),
      )
      self.assert_eq(
          pser.swaplevel("number", "size"),
          psser.swaplevel("number", "size"),
      )
      self.assert_eq(
          pser.swaplevel("color", "size"),
          psser.swaplevel("color", "size"),
      )
  
      # Error conditions
      self.assertRaises(
          AssertionError, lambda: ps.Series([1, 2]).swaplevel()
      )
      self.assertRaises(IndexError, lambda: psser.swaplevel(0, 9))
      self.assertRaises(
          KeyError, lambda: psser.swaplevel("not_number", "color")
      )
      self.assertRaises(
          AssertionError, lambda: psser.swaplevel(copy=False)
      )
  
imports: import unittest
  import numpy
  import pandas
  from pyspark import pandas
  from pyspark.testing.pandasutils import ComparisonTestBase
  from pyspark.testing.sqlutils import SQLTestUtils
label_desc: Use image node_id 11 for calling the SeriesIndexMixin obj's underlying member method code with example usage: obj.test_swaplevel() without return types