code: def test_split_on_nan_with_infinite_values():
      # Make sure the split on nan situations are respected even when there are
      # samples with +inf values (we set the threshold to +inf when we have a
      # split on nan so this test makes sure this does not introduce edge-case
      # bugs). We need to use the private API so that we can also test
      # predict_binned().
  
      X = np.array([0, 1, np.inf, np.nan, np.nan]).reshape(-1, 1)
      # the gradient values will force a split on nan situation
      gradients = np.array([0, 0, 0, 100, 100], dtype=G_H_DTYPE)
      hessians = np.ones(shape=1, dtype=G_H_DTYPE)
  
      bin_mapper = _BinMapper()
      X_binned = bin_mapper.fit_transform(X)
  
      n_bins_non_missing = 3
      has_missing_values = True
      grower = TreeGrower(
          X_binned,
          gradients,
          hessians,
          n_bins_non_missing=n_bins_non_missing,
          has_missing_values=has_missing_values,
          min_samples_leaf=1,
          n_threads=n_threads,
      )
  
      grower.grow()
  
      predictor = grower.make_predictor(
          binning_thresholds=bin_mapper.bin_thresholds_
      )
  
      # sanity check: this was a split on nan
      assert predictor.nodes[0]["num_threshold"] == np.inf
      assert (
          predictor.nodes[0]["bin_threshold"] == n_bins_non_missing - 1
      )
  
      (
          known_cat_bitsets,
          f_idx_map,
      ) = bin_mapper.make_known_categories_bitsets()
  
      # Make sure in particular that the +inf sample is mapped to the left child
      # Note that lightgbm "fails" here and will assign the inf sample to the
      # right child, even though it's a "split on nan" situation.
      predictions = predictor.predict(
          X, known_cat_bitsets, f_idx_map, n_threads
      )
      predictions_binned = predictor.predict_binned(
          X_binned,
          missing_values_bin_idx=bin_mapper.missing_values_bin_idx_,
          n_threads=n_threads,
      )
      np.testing.assert_allclose(predictions, -gradients)
      np.testing.assert_allclose(predictions_binned, -gradients)
  
imports: import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal
  from pytest import approx
  from sklearn.ensemble._hist_gradient_boosting.binning import _BinMapper
  from sklearn.ensemble._hist_gradient_boosting.common import G_H_DTYPE, X_BINNED_DTYPE, X_BITSET_INNER_DTYPE, X_DTYPE, Y_DTYPE
  from sklearn.ensemble._hist_gradient_boosting.grower import TreeGrower
  from sklearn.preprocessing import OneHotEncoder
  from sklearn.utils._openmp_helpers import _openmp_effective_n_threads
label_desc: Use image node_id 12 for calling a global function with example usage: test_split_on_nan_with_infinite_values() without return types