code: def test_loc(self):
      psdf = self.psdf
      pdf = self.pdf
  
      self.assert_eq(psdf.loc[5:5], pdf.loc[5:5])
      self.assert_eq(psdf.loc[3:8], pdf.loc[3:8])
      self.assert_eq(psdf.loc[:8], pdf.loc[:8])
      self.assert_eq(psdf.loc[3:], pdf.loc[3:])
      self.assert_eq(psdf.loc[[5]], pdf.loc[[5]])
      self.assert_eq(psdf.loc[:], pdf.loc[:])
  
      # TODO?: self.assert_eq(psdf.loc[[3, 4, 1, 8]], pdf.loc[[3, 4, 1, 8]])
      # TODO?: self.assert_eq(psdf.loc[[3, 4, 1, 9]], pdf.loc[[3, 4, 1, 9]])
      # TODO?: self.assert_eq(psdf.loc[np.array([3, 4, 1, 9])], pdf.loc[np.array([3, 4, 1, 9])])
  
      self.assert_eq(psdf.a.loc[5:5], pdf.a.loc[5:5])
      self.assert_eq(psdf.a.loc[3:8], pdf.a.loc[3:8])
      self.assert_eq(psdf.a.loc[:8], pdf.a.loc[:8])
      self.assert_eq(psdf.a.loc[3:], pdf.a.loc[3:])
      self.assert_eq(psdf.a.loc[[5]], pdf.a.loc[[5]])
  
      # TODO?: self.assert_eq(psdf.a.loc[[3, 4, 1, 8]], pdf.a.loc[[3, 4, 1, 8]])
      # TODO?: self.assert_eq(psdf.a.loc[[3, 4, 1, 9]], pdf.a.loc[[3, 4, 1, 9]])
      # TODO?: self.assert_eq(psdf.a.loc[np.array([3, 4, 1, 9])],
      #                       pdf.a.loc[np.array([3, 4, 1, 9])])
  
      self.assert_eq(psdf.a.loc[[]], pdf.a.loc[[]])
      self.assert_eq(psdf.a.loc[np.array([])], pdf.a.loc[np.array([])])
  
      self.assert_eq(psdf.loc[1000:], pdf.loc[1000:])
      self.assert_eq(psdf.loc[-2000:-1000], pdf.loc[-2000:-1000])
  
      self.assert_eq(psdf.loc[5], pdf.loc[5])
      self.assert_eq(psdf.loc[9], pdf.loc[9])
      self.assert_eq(psdf.a.loc[5], pdf.a.loc[5])
      self.assert_eq(psdf.a.loc[9], pdf.a.loc[9])
  
      self.assertRaises(KeyError, lambda: psdf.loc[10])
      self.assertRaises(KeyError, lambda: psdf.a.loc[10])
  
      # monotonically increasing index test
      pdf = pd.DataFrame(
          {"a": [1, 2, 3, 4, 5, 6, 7, 8, 9]},
          index=[0, 1, 1, 2, 2, 2, 4, 5, 6],
      )
      psdf = ps.from_pandas(pdf)
  
      self.assert_eq(psdf.loc[:2], pdf.loc[:2])
      self.assert_eq(psdf.loc[:3], pdf.loc[:3])
      self.assert_eq(psdf.loc[3:], pdf.loc[3:])
      self.assert_eq(psdf.loc[4:], pdf.loc[4:])
      self.assert_eq(psdf.loc[3:2], pdf.loc[3:2])
      self.assert_eq(psdf.loc[-1:2], pdf.loc[-1:2])
      self.assert_eq(psdf.loc[3:10], pdf.loc[3:10])
  
      # monotonically decreasing index test
      pdf = pd.DataFrame(
          {"a": [1, 2, 3, 4, 5, 6, 7, 8, 9]},
          index=[6, 5, 5, 4, 4, 4, 2, 1, 0],
      )
      psdf = ps.from_pandas(pdf)
  
      self.assert_eq(psdf.loc[:4], pdf.loc[:4])
      self.assert_eq(psdf.loc[:3], pdf.loc[:3])
      self.assert_eq(psdf.loc[3:], pdf.loc[3:])
      self.assert_eq(psdf.loc[2:], pdf.loc[2:])
      self.assert_eq(psdf.loc[2:3], pdf.loc[2:3])
      self.assert_eq(psdf.loc[2:-1], pdf.loc[2:-1])
      self.assert_eq(psdf.loc[10:3], pdf.loc[10:3])
  
      # test when type of key is string and given value is not included in key
      pdf = pd.DataFrame({"a": [1, 2, 3]}, index=["a", "b", "d"])
      psdf = ps.from_pandas(pdf)
  
      self.assert_eq(psdf.loc["a":"z"], pdf.loc["a":"z"])
  
      # KeyError when index is not monotonic increasing or decreasing
      # and specified values don't exist in index
      psdf = ps.DataFrame(
          [[1, 2], [4, 5], [7, 8]],
          index=["cobra", "viper", "sidewinder"],
      )
  
      self.assertRaises(KeyError, lambda: psdf.loc["cobra":"koalas"])
      self.assertRaises(KeyError, lambda: psdf.loc["koalas":"viper"])
  
      psdf = ps.DataFrame([[1, 2], [4, 5], [7, 8]], index=[10, 30, 20])
  
      self.assertRaises(KeyError, lambda: psdf.loc[0:30])
      self.assertRaises(KeyError, lambda: psdf.loc[10:100])
  
imports: import unittest
  import numpy
  import pandas
  from pyspark import pandas
  from pyspark.testing.pandasutils import PandasOnSparkTestCase
  from pyspark.testing.sqlutils import SQLTestUtils
label_desc: Use image node_id 5 for calling the IndexingLocMixin obj's underlying member method code with example usage: obj.test_loc() without return types