class_docstr: Unit tests using pathlib.Path for file interaction.
class_docstr_tok: ["Unit","tests","using","pathlib.Path","for","file","interaction","."]
docstr: Saving to a binary file using pathlib from a DMatrix.
docstr_tok: ["Saving","to","a","binary","file","using","pathlib","from","a","DMatrix","."]
code: def test_DMatrix_save_to_path(self):
      """Saving to a binary file using pathlib from a DMatrix."""
      data = np.random.randn(100, 2)
      target = np.array([0, 1] * 50)
      features = ["Feature1", "Feature2"]
  
      dm = xgb.DMatrix(data, label=target, feature_names=features)
  
      # save, assert exists, remove file
      binary_path = Path("dtrain.bin")
      dm.save_binary(binary_path)
      assert binary_path.exists()
      Path.unlink(binary_path)
  
imports: import json
  import os
  import pathlib
  import tempfile
  from pathlib import Path
  import numpy
  import pytest
  import xgboost
  from xgboost import testing
label_desc: Use image node_id 2 for calling the TestBasicPathLike obj's underlying member method code with example usage: obj.test_DMatrix_save_to_path() without return types