code: def test_categorical():
      X, y = tm.make_categorical(
          n_samples=32, n_features=2, n_categories=3, onehot=False
      )
      ft = ["c"] * X.shape[1]
      reg = xgb.XGBRegressor(
          feature_types=ft,
          max_cat_to_onehot=1,
          enable_categorical=True,
      )
      reg.fit(X.values, y, eval_set=[(X.values, y)])
      from_cat = reg.evals_result()["validation_0"]["rmse"]
      predt_cat = reg.predict(X.values)
      assert reg.get_booster().feature_types == ft
      with tempfile.TemporaryDirectory() as tmpdir:
          path = os.path.join(tmpdir, "model.json")
          reg.save_model(path)
          reg = xgb.XGBRegressor()
          reg.load_model(path)
          assert reg.feature_types == ft
  
      onehot, y = tm.make_categorical(
          n_samples=32, n_features=2, n_categories=3, onehot=True
      )
      reg = xgb.XGBRegressor()
      reg.fit(onehot, y, eval_set=[(onehot, y)])
      from_enc = reg.evals_result()["validation_0"]["rmse"]
      predt_enc = reg.predict(onehot)
  
      np.testing.assert_allclose(from_cat, from_enc)
      np.testing.assert_allclose(predt_cat, predt_enc)
  
imports: import json
  import os
  import pickle
  import random
  import tempfile
  import warnings
  from typing import Callable, Optional
  import numpy
  import pytest
  from sklearn.utils.estimator_checks import parametrize_with_checks
  import xgboost
  from xgboost import testing
  from xgboost.testing.ranking import run_ranking_categorical, run_ranking_qid_df
  from xgboost.testing.shared import get_feature_weights, validate_data_initialization
  from xgboost.testing.updater import get_basescore
label_desc: Use image node_id 49 for calling a global function with example usage: test_categorical() without return types