code: def test_dataframe_loc():
      raw = pd.DataFrame(
          [[1, 3, 3], [4, 2, 6], [7, 8, 9]],
          index=["a1", "a2", "a3"],
          columns=["x", "y", "z"],
      )
      df = md.DataFrame(raw, chunk_size=2)
      raw2 = raw.copy()
      raw2.reset_index(inplace=True, drop=True)
      df3 = md.DataFrame(raw2, chunk_size=2)
      s = pd.Series([1, 3, 5], index=["a1", "a2", "a3"])
      series = md.Series(s, chunk_size=2)
  
      # test return scalar
      df2 = df.loc["a1", "z"]
      assert isinstance(df2, Tensor)
      assert df2.shape == ()
      assert df2.dtype == raw["z"].dtype
  
      df2 = tile(df2)
      assert len(df2.chunks) == 1
      assert isinstance(df2.chunks[0], TENSOR_CHUNK_TYPE)
  
      # test return series for index axis
      df2 = df.loc[:, "y"]
      assert isinstance(df2, Series)
      assert df2.shape == (3,)
      pd.testing.assert_index_equal(
          df2.index_value.to_pandas(), df.index_value.to_pandas()
      )
      assert df2.name == "y"
      assert df2.index_value.key == df.index_value.key
  
      df2 = tile(df2)
      assert len(df2.chunks) == 2
      for c in df2.chunks:
          assert isinstance(c, SERIES_CHUNK_TYPE)
          assert isinstance(c.index_value.to_pandas(), type(raw.index))
          assert c.name == "y"
          assert c.dtype == raw["y"].dtype
  
      # test return series for column axis
      df2 = df.loc["a2", :]
      assert isinstance(df2, Series)
      assert df2.shape == (3,)
      pd.testing.assert_index_equal(
          df2.index_value.to_pandas(), df.columns_value.to_pandas()
      )
      assert df2.name == "a2"
  
      df2 = tile(df2)
      assert len(df2.chunks) == 2
      for c in df2.chunks:
          assert isinstance(c, SERIES_CHUNK_TYPE)
          assert isinstance(
              c.index_value.to_pandas(), type(raw.columns)
          )
          assert c.name == "a2"
          assert c.dtype == raw.loc["a2"].dtype
  
      # test slice
      df2 = df.loc["a2":"a3", "y":"z"]
      assert isinstance(df2, DataFrame)
      assert df2.shape == (np.nan, 2)
      pd.testing.assert_index_equal(
          df2.index_value.to_pandas(), df.index_value.to_pandas()
      )
      assert df2.index_value.key != df.index_value.key
      pd.testing.assert_index_equal(
          df2.columns_value.to_pandas(), raw.loc[:, "y":"z"].columns
      )
      pd.testing.assert_series_equal(
          df2.dtypes, raw.loc[:, "y":"z"].dtypes
      )
  
      # test fancy index on index axis
      df2 = df.loc[["a3", "a2"], [True, False, True]]
      assert isinstance(df2, DataFrame)
      assert df2.shape == (2, 2)
      pd.testing.assert_index_equal(
          df2.index_value.to_pandas(), df.index_value.to_pandas()
      )
      assert df2.index_value.key != df.index_value.key
      pd.testing.assert_index_equal(
          df2.columns_value.to_pandas(),
          raw.loc[:, [True, False, True]].columns,
      )
      pd.testing.assert_series_equal(
          df2.dtypes, raw.loc[:, [True, False, True]].dtypes
      )
  
      # test fancy index which is md.Series on index axis
      df2 = df.loc[md.Series(["a3", "a2"]), [True, False, True]]
      assert isinstance(df2, DataFrame)
      assert df2.shape == (2, 2)
      pd.testing.assert_index_equal(
          df2.index_value.to_pandas(), df.index_value.to_pandas()
      )
      assert df2.index_value.key != df.index_value.key
      pd.testing.assert_index_equal(
          df2.columns_value.to_pandas(),
          raw.loc[:, [True, False, True]].columns,
      )
      pd.testing.assert_series_equal(
          df2.dtypes, raw.loc[:, [True, False, True]].dtypes
      )
  
      # test fancy index on columns axis
      df2 = df.loc[[True, False, True], ["z", "x", "y"]]
      assert isinstance(df2, DataFrame)
      assert df2.shape == (2, 3)
      pd.testing.assert_index_equal(
          df2.index_value.to_pandas(), df.index_value.to_pandas()
      )
      assert df2.index_value.key != df.index_value.key
      pd.testing.assert_index_equal(
          df2.columns_value.to_pandas(),
          raw.loc[:, ["z", "x", "y"]].columns,
      )
      pd.testing.assert_series_equal(
          df2.dtypes, raw.loc[:, ["z", "x", "y"]].dtypes
      )
  
      df2 = tile(df2)
      assert len(df2.chunks) == 2
      for c in df2.chunks:
          assert isinstance(c, DATAFRAME_CHUNK_TYPE)
          pd.testing.assert_index_equal(
              c.index_value.to_pandas(), df.index_value.to_pandas()
          )
          assert c.index_value.key != df.index_value.key
          pd.testing.assert_index_equal(
              c.columns_value.to_pandas(),
              raw.loc[:, ["z", "x", "y"]].columns,
          )
          pd.testing.assert_series_equal(
              c.dtypes, raw.loc[:, ["z", "x", "y"]].dtypes
          )
  
      df2 = df.loc[md.Series([True, False, True])]
      assert isinstance(df2, DataFrame)
      assert df2.shape == (np.nan, 3)
      pd.testing.assert_index_equal(
          df2.index_value.to_pandas(), df.index_value.to_pandas()
      )
      assert df2.index_value.key != df.index_value.key
      pd.testing.assert_index_equal(
          df2.columns_value.to_pandas(), raw.columns
      )
      pd.testing.assert_series_equal(df2.dtypes, raw.dtypes)
  
      df2 = df3.loc[md.Series([True, False, True])]
      assert isinstance(df2, DataFrame)
      assert df2.shape == (np.nan, 3)
      assert isinstance(
          df2.index_value.to_pandas(),
          type(raw.loc[[True, False, True]].index),
      )
      assert df2.index_value.key != df3.index_value.key
      pd.testing.assert_index_equal(
          df2.columns_value.to_pandas(), raw.columns
      )
      pd.testing.assert_series_equal(df2.dtypes, raw.dtypes)
  
      df2 = df3.loc[md.Series([2, 1])]
      assert isinstance(df2, DataFrame)
      assert df2.shape == (2, 3)
      assert isinstance(
          df2.index_value.to_pandas(), type(raw2.loc[[2, 1]].index)
      )
      assert df2.index_value.key != df3.index_value.key
      pd.testing.assert_index_equal(
          df2.columns_value.to_pandas(), raw.columns
      )
      pd.testing.assert_series_equal(df2.dtypes, raw.dtypes)
  
      series2 = series.loc["a2"]
      assert isinstance(series2, Tensor)
      assert series2.shape == ()
      assert series2.dtype == s.dtype
  
      series2 = series.loc[["a2", "a3"]]
      assert isinstance(series2, Series)
      assert series2.shape == (2,)
      assert series2.dtype == s.dtype
      assert series2.name == s.name
  
      with pytest.raises(IndexingError):
          _ = df.loc["a1", "z", ...]
  
      with pytest.raises(NotImplementedError):
          _ = df.loc[:, md.Series([True, False, True])]
  
      with pytest.raises(KeyError):
          _ = df.loc[:, ["non_exist"]]
  
      # test loc chunk's index_value
      raw = pd.DataFrame(
          np.random.rand(9, 2),
          index=["a1", "a2", "a3"] * 3,
          columns=["x", "y"],
      )
      df = md.DataFrame(raw, chunk_size=4)
      loc_df = df.loc[:, ["x"]]
      tiled_df, tiled_loc_df = tile(df, loc_df)
      # for full slice, index_value should be same as input chunk
      for loc_chunk, chunk in zip(tiled_loc_df.chunks, tiled_df.chunks):
          assert loc_chunk.index_value.key == chunk.index_value.key
  
      # test loc on filtered df
      df2 = df[df["x"] < 1]
      loc_df = df2.loc[:, ["y", "x"]]
      tiled_loc_df = tile(loc_df)
      assert len(tiled_loc_df.chunks) == 3
  
imports: import numpy
  import pandas
  import pytest
  from ....None import dataframe
  from ....None import tensor
  from ....core import tile
  from ....tensor.core import TENSOR_CHUNK_TYPE, TENSOR_TYPE, Tensor
  from ...core import SERIES_CHUNK_TYPE, SERIES_TYPE, Series, DATAFRAME_TYPE, DataFrame, DATAFRAME_CHUNK_TYPE
  from ...datasource.from_tensor import dataframe_from_tensor
  from ..iloc import DataFrameIlocGetItem, DataFrameIlocSetItem, IndexingError, HeadTailOptimizedOperandMixin
  from ..loc import DataFrameLocGetItem
label_desc: Use image node_id 4 for calling a global function with example usage: test_dataframe_loc() without return types