code: def test_indexing(self, df):
      df1 = df.set_index("month")
      yield df1
  
      yield df.set_index("month", drop=False)
      yield df.set_index("month", append=True)
      yield df.set_index(["year", "month"])
      yield df.set_index(["year", "month"], drop=False)
      yield df.set_index(["year", "month"], append=True)
  
      yield df1.set_index("year", drop=False, append=True)
  
      df2 = df1.copy()
      df2.set_index("year", append=True, inplace=True)
      yield df2
  
      self.assertRaisesRegex(
          KeyError, "unknown", lambda: df.set_index("unknown")
      )
      self.assertRaisesRegex(
          KeyError,
          "unknown",
          lambda: df.set_index(["month", "unknown"]),
      )
  
      for d in [df, df1, df2]:
          yield d.reset_index()
          yield d.reset_index(drop=True)
  
      yield df1.reset_index(level=0)
      yield df2.reset_index(level=1)
      yield df2.reset_index(level=[1, 0])
      yield df1.reset_index(level="month")
      yield df2.reset_index(level="year")
      yield df2.reset_index(level=["month", "year"])
      yield df2.reset_index(level="month", drop=True)
      yield df2.reset_index(level=["month", "year"], drop=True)
  
      self.assertRaisesRegex(
          IndexError,
          "Too many levels: Index has only 1 level, not 3",
          lambda: df1.reset_index(level=2),
      )
      self.assertRaisesRegex(
          IndexError,
          "Too many levels: Index has only 1 level, not 4",
          lambda: df1.reset_index(level=[3, 2]),
      )
      self.assertRaisesRegex(
          KeyError,
          "unknown.*month",
          lambda: df1.reset_index(level="unknown"),
      )
      self.assertRaisesRegex(
          KeyError,
          "Level unknown not found",
          lambda: df2.reset_index(level="unknown"),
      )
  
      df3 = df2.copy()
      df3.reset_index(inplace=True)
      yield df3
  
      yield df1.sale.reset_index()
      yield df1.sale.reset_index(level=0)
      yield df2.sale.reset_index(level=[1, 0])
      yield df1.sale.reset_index(drop=True)
      yield df1.sale.reset_index(name="s")
      yield df1.sale.reset_index(name="s", drop=True)
  
      s = df1.sale
      self.assertRaisesRegex(
          TypeError,
          "Cannot reset_index inplace on a Series to create a DataFrame",
          lambda: s.reset_index(inplace=True),
      )
      s.reset_index(drop=True, inplace=True)
      yield s
      yield df1
  
      # multi-index columns
      df4 = df.copy()
      df4.columns = pd.MultiIndex.from_tuples(
          [("cal", "month"), ("cal", "year"), ("num", "sale")]
      )
      df5 = df4.set_index(("cal", "month"))
      yield df5
      yield df4.set_index([("cal", "month"), ("num", "sale")])
  
      self.assertRaises(
          KeyError, lambda: df5.reset_index(level=("cal", "month"))
      )
  
      yield df5.reset_index(level=[("cal", "month")])
  
      # non-string names
      df6 = df.copy()
      df6.columns = [10.0, 20.0, 30.0]
      df7 = df6.set_index(10.0)
      yield df7
      yield df6.set_index([10.0, 30.0])
  
      yield df7.reset_index(level=10.0)
      yield df7.reset_index(level=[10.0])
  
      df8 = df.copy()
      df8.columns = pd.MultiIndex.from_tuples(
          [(10, "month"), (10, "year"), (20, "sale")]
      )
      df9 = df8.set_index((10, "month"))
      yield df9
      yield df8.set_index([(10, "month"), (20, "sale")])
  
      yield df9.reset_index(level=[(10, "month")])
  
file_path: spark/python/pyspark/pandas/tests/indexes/test_indexing_basic.py
imports: import unittest
  import pandas
  from pyspark import pandas
  from pyspark.testing.pandasutils import PandasOnSparkTestCase, compare_both
label_desc: Use image node_id 3 for calling the BasicIndexingTestsMixin obj's underlying member method code with example usage: obj.test_indexing(df) without return types