code: def test_pandas(self, data_split_mode=DataSplitMode.ROW):
      world_size = xgb.collective.get_world_size()
      df = pd.DataFrame(
          [[1, 2.0, True], [2, 3.0, False]], columns=["a", "b", "c"]
      )
      dm = xgb.DMatrix(
          df, label=pd.Series([1, 2]), data_split_mode=data_split_mode
      )
      assert dm.num_row() == 2
      if data_split_mode == DataSplitMode.ROW:
          assert dm.feature_names == ["a", "b", "c"]
          assert dm.feature_types == ["int", "float", "i"]
          assert dm.num_col() == 3
      else:
          assert dm.feature_names == tm.column_split_feature_names(
              ["a", "b", "c"], world_size
          )
          assert dm.feature_types == ["int", "float", "i"] * world_size
          assert dm.num_col() == 3 * world_size
      np.testing.assert_array_equal(dm.get_label(), np.array([1, 2]))
  
      # overwrite feature_names and feature_types
      dm = xgb.DMatrix(
          df,
          label=pd.Series([1, 2]),
          feature_names=["x", "y", "z"],
          feature_types=["q", "q", "q"],
          data_split_mode=data_split_mode,
      )
      assert dm.num_row() == 2
      if data_split_mode == DataSplitMode.ROW:
          assert dm.feature_names == ["x", "y", "z"]
          assert dm.feature_types == ["q", "q", "q"]
          assert dm.num_col() == 3
      else:
          assert dm.feature_names == tm.column_split_feature_names(
              ["x", "y", "z"], world_size
          )
          assert dm.feature_types == ["q", "q", "q"] * world_size
          assert dm.num_col() == 3 * world_size
  
      # incorrect dtypes
      df = pd.DataFrame(
          [[1, 2.0, "x"], [2, 3.0, "y"]], columns=["a", "b", "c"]
      )
      with pytest.raises(ValueError):
          xgb.DMatrix(df, data_split_mode=data_split_mode)
  
      # numeric columns
      df = pd.DataFrame([[1, 2.0, True], [2, 3.0, False]])
      dm = xgb.DMatrix(
          df, label=pd.Series([1, 2]), data_split_mode=data_split_mode
      )
      assert dm.num_row() == 2
      if data_split_mode == DataSplitMode.ROW:
          assert dm.feature_names == ["0", "1", "2"]
          assert dm.feature_types == ["int", "float", "i"]
          assert dm.num_col() == 3
      else:
          assert dm.feature_names == tm.column_split_feature_names(
              ["0", "1", "2"], world_size
          )
          assert dm.feature_types == ["int", "float", "i"] * world_size
          assert dm.num_col() == 3 * world_size
      np.testing.assert_array_equal(dm.get_label(), np.array([1, 2]))
  
      df = pd.DataFrame([[1, 2.0, 1], [2, 3.0, 1]], columns=[4, 5, 6])
      dm = xgb.DMatrix(
          df, label=pd.Series([1, 2]), data_split_mode=data_split_mode
      )
      assert dm.num_row() == 2
      if data_split_mode == DataSplitMode.ROW:
          assert dm.feature_names == ["4", "5", "6"]
          assert dm.feature_types == ["int", "float", "int"]
          assert dm.num_col() == 3
      else:
          assert dm.feature_names == tm.column_split_feature_names(
              ["4", "5", "6"], world_size
          )
          assert (
              dm.feature_types == ["int", "float", "int"] * world_size
          )
          assert dm.num_col() == 3 * world_size
  
      df = pd.DataFrame({"A": ["X", "Y", "Z"], "B": [1, 2, 3]})
      dummies = pd.get_dummies(df)
      #    B  A_X  A_Y  A_Z
      # 0  1    1    0    0
      # 1  2    0    1    0
      # 2  3    0    0    1
      result, _, _ = xgb.data._transform_pandas_df(
          dummies, enable_categorical=False
      )
      exp = np.array(
          [
              [1.0, 1.0, 0.0, 0.0],
              [2.0, 0.0, 1.0, 0.0],
              [3.0, 0.0, 0.0, 1.0],
          ]
      ).T
      np.testing.assert_array_equal(result.columns, exp)
      dm = xgb.DMatrix(dummies, data_split_mode=data_split_mode)
      assert dm.num_row() == 3
      if data_split_mode == DataSplitMode.ROW:
          assert dm.feature_names == ["B", "A_X", "A_Y", "A_Z"]
          if int(pd.__version__[0]) >= 2:
              assert dm.feature_types == ["int", "i", "i", "i"]
          else:
              assert dm.feature_types == ["int", "int", "int", "int"]
          assert dm.num_col() == 4
      else:
          assert dm.feature_names == tm.column_split_feature_names(
              ["B", "A_X", "A_Y", "A_Z"], world_size
          )
          if int(pd.__version__[0]) >= 2:
              assert (
                  dm.feature_types
                  == ["int", "i", "i", "i"] * world_size
              )
          else:
              assert (
                  dm.feature_types
                  == ["int", "int", "int", "int"] * world_size
              )
          assert dm.num_col() == 4 * world_size
  
      df = pd.DataFrame({"A=1": [1, 2, 3], "A=2": [4, 5, 6]})
      dm = xgb.DMatrix(df, data_split_mode=data_split_mode)
      assert dm.num_row() == 3
      if data_split_mode == DataSplitMode.ROW:
          assert dm.feature_names == ["A=1", "A=2"]
          assert dm.feature_types == ["int", "int"]
          assert dm.num_col() == 2
      else:
          assert dm.feature_names == tm.column_split_feature_names(
              ["A=1", "A=2"], world_size
          )
          assert dm.feature_types == ["int", "int"] * world_size
          assert dm.num_col() == 2 * world_size
  
      df_int = pd.DataFrame([[1, 1.1], [2, 2.2]], columns=[9, 10])
      dm_int = xgb.DMatrix(df_int, data_split_mode=data_split_mode)
      df_range = pd.DataFrame(
          [[1, 1.1], [2, 2.2]], columns=range(9, 11, 1)
      )
      dm_range = xgb.DMatrix(df_range, data_split_mode=data_split_mode)
      if data_split_mode == DataSplitMode.ROW:
          assert dm_int.feature_names == ["9", "10"]  # assert not "9 "
      else:
          assert dm_int.feature_names == tm.column_split_feature_names(
              ["9", "10"], world_size
          )
      assert dm_int.feature_names == dm_range.feature_names
  
      # test MultiIndex as columns
      df = pd.DataFrame(
          [(1, 2, 3, 4, 5, 6), (6, 5, 4, 3, 2, 1)],
          columns=pd.MultiIndex.from_tuples(
              (
                  ("a", 1),
                  ("a", 2),
                  ("a", 3),
                  ("b", 1),
                  ("b", 2),
                  ("b", 3),
              )
          ),
      )
      dm = xgb.DMatrix(df, data_split_mode=data_split_mode)
      assert dm.num_row() == 2
      if data_split_mode == DataSplitMode.ROW:
          assert dm.feature_names == [
              "a 1",
              "a 2",
              "a 3",
              "b 1",
              "b 2",
              "b 3",
          ]
          assert dm.feature_types == [
              "int",
              "int",
              "int",
              "int",
              "int",
              "int",
          ]
          assert dm.num_col() == 6
      else:
          assert dm.feature_names == tm.column_split_feature_names(
              ["a 1", "a 2", "a 3", "b 1", "b 2", "b 3"], world_size
          )
          assert (
              dm.feature_types
              == ["int", "int", "int", "int", "int", "int"] * world_size
          )
          assert dm.num_col() == 6 * world_size
  
      # test Index as columns
      df = pd.DataFrame([[1, 1.1], [2, 2.2]], columns=pd.Index([1, 2]))
      Xy = xgb.DMatrix(df, data_split_mode=data_split_mode)
      if data_split_mode == DataSplitMode.ROW:
          np.testing.assert_equal(
              np.array(Xy.feature_names), np.array(["1", "2"])
          )
      else:
          np.testing.assert_equal(
              np.array(Xy.feature_names),
              np.array(
                  tm.column_split_feature_names(["1", "2"], world_size)
              ),
          )
  
      # test pandas series
      data_series = pd.Series([1, 2, 3, 4, 5])
      dm = xgb.DMatrix(data_series, data_split_mode=data_split_mode)
      assert dm.num_row() == 5
      if data_split_mode == DataSplitMode.ROW:
          assert dm.num_col() == 1
      else:
          assert dm.num_col() == 1 * world_size
  
imports: from typing import Type
  import numpy
  import pytest
  import xgboost
  from xgboost import testing
  from xgboost.core import DataSplitMode
  from xgboost.testing.data import pd_arrow_dtypes, pd_dtypes, run_base_margin_info
label_desc: Use image node_id 1 for calling the TestPandas obj's underlying member method code with example usage: obj.test_pandas(data_split_mode) without return types