Skip to content

BUG: HGB threshold extraction raises IndexError on valid all-missing support #35164

Closed

Description

@deepkilo

Reporter statement

A valid column with missing values should retain its original business semantics rather than cause training to fail with IndexError.

Original statement supplied by the human reporter:

合法的缺失列应该保持原业务语义而不应该导致训练IndexError

Context: correctness validation of machine-learning factors for quantitative research.

Steps / Code to Reproduce

import numpy as np
from sklearn.ensemble import HistGradientBoostingRegressor

X = np.c_[np.arange(20.0), np.full(20, np.nan)]
y = np.arange(20.0)
HistGradientBoostingRegressor(
    max_iter=2, min_samples_leaf=2, early_stopping=False,
).fit(X, y)

Expected Results

Keep the feature's missing-value semantics; no training IndexError.

Execution evidence and scope

The following is diagnostic-process output, not a claim of a clean full-main installation. The exact main Python threshold function was replayed in an isolated process with the existing locally patched 1.9.1 native modules. No production module was changed.

{
  "scope": "Exact current-main Python threshold function in an isolated process with local 1.9.1.post1 native modules; not a complete current-main build",
  "source": {
    "sha": "85593ca7a07a9956ac891f6bfc3fedca53b74f72",
    "source": "sklearn/ensemble/_hist_gradient_boosting/binning.py"
  },
  "python": "3.15.0",
  "sklearn_native": "1.9.1.post1",
  "cases": [
    {
      "case": "all_missing_helper",
      "outcome": "IndexError",
      "message": "index 0 is out of bounds for axis 0 with size 0"
    },
    {
      "case": "positive_total_weight_empty_numeric_support",
      "outcome": "IndexError",
      "message": "index 0 is out of bounds for axis 0 with size 0"
    },
    {
      "case": "public_fit_all_missing_feature",
      "outcome": "IndexError",
      "message": "index 0 is out of bounds for axis 0 with size 0"
    }
  ]
}

Main source: https://github.com/scikit-learn/scikit-learn/blob/85593ca7a07a9956ac891f6bfc3fedca53b74f72/sklearn/ensemble/_hist_gradient_boosting/binning.py

Actual Results

Full source-replay traceback (local path prefixes redacted)
joblib.externals.loky.process_executor._RemoteTraceback: 
"""
Traceback (most recent call last):
  File "<site-packages>/joblib/_utils.py", line 109, in __call__
    return self.func(**kwargs)
           ~~~~~~~~~^^^^^^^^^^
  File "<site-packages>/joblib/parallel.py", line 607, in __call__
    return [func(*args, **kwargs) for func, args, kwargs in self.items]
            ~~~~^^^^^^^^^^^^^^^^^
  File "<site-packages>/sklearn/utils/parallel.py", line 184, in __call__
    return self.function(*args, **kwargs)
           ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "<upstream-main>/sklearn-main-binning.py", line 80, in _find_binning_thresholds
    distinct_mask[0] = True
    ~~~~~~~~~~~~~^^^
IndexError: index 0 is out of bounds for axis 0 with size 0
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 7, in <module>
  File "<site-packages>/sklearn/base.py", line 1403, in wrapper
    return fit_method(estimator, *args, **kwargs)
  File "<site-packages>/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py", line 603, in fit
    X_binned_train = self._bin_data(
        X_train, sample_weight_train, is_training_data=True
    )
  File "<site-packages>/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py", line 1122, in _bin_data
    X_binned = self._bin_mapper.fit_transform(
        X, sample_weight=sample_weight
    )  # F-aligned array
  File "<site-packages>/sklearn/utils/_set_output.py", line 327, in wrapped
    data_to_wrap = f(self, X, *args, **kwargs)
  File "<site-packages>/sklearn/base.py", line 969, in fit_transform
    return self.fit(X, **fit_params).transform(X)
           ~~~~~~~~^^^^^^^^^^^^^^^^^
  File "<site-packages>/sklearn/ensemble/_hist_gradient_boosting/binning.py", line 291, in fit
    non_cat_thresholds = Parallel(n_jobs=self.n_threads, backend="threading")(
        delayed(_find_binning_thresholds)(
    ...<3 lines>...
        if not self.is_categorical_[f_idx]
    )
  File "<site-packages>/sklearn/utils/parallel.py", line 91, in __call__
    return super().__call__(iterable_with_config_and_warning_filters)
           ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<site-packages>/joblib/parallel.py", line 2098, in __call__
    return output if self.return_generator else list(output)
                                                ~~~~^^^^^^^^
  File "<site-packages>/joblib/parallel.py", line 1704, in _get_outputs
    yield from self._retrieve()
  File "<site-packages>/joblib/parallel.py", line 1806, in _retrieve
    self._raise_error_fast()
    ~~~~~~~~~~~~~~~~~~~~~~^^
  File "<site-packages>/joblib/parallel.py", line 1885, in _raise_error_fast
    error_job.get_result(self.timeout)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "<site-packages>/joblib/parallel.py", line 780, in get_result
    return self._return_or_raise()
           ~~~~~~~~~~~~~~~~~~~~~^^
  File "<site-packages>/joblib/parallel.py", line 795, in _return_or_raise
    raise self._result
IndexError: index 0 is out of bounds for axis 0 with size 0

Versions

sklearn.show_versions() for the native host environment

System:
    python: 3.15.0 | packaged by conda-forge | (main, Oct 12 2026, 17:36:43) [GCC 15.3.0]
executable: <runtime-prefix>/bin/python
   machine: Linux-6.17.0-1023-oem-x86_64-with-glibc2.39

Python dependencies:
      sklearn: 1.9.1.post1
          pip: 26.2.1
   setuptools: 84.0.0
        numpy: 2.5.4
        scipy: 1.18.1.post1
       Cython: None
       pandas: 3.0.6.post1
   matplotlib: 3.11.2
       joblib: 1.6.0
threadpoolctl: 3.7.0.post1
     narwhals: 2.27.1

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 32
         prefix: libscipy_openblas
       filepath: <runtime-prefix>/lib/python3.15/site-packages/numpy.libs/libscipy_openblas64_-f48b354e.so
        version: 0.3.34.106.0
threading_layer: pthreads
   architecture: SkylakeX

       user_api: openmp
   internal_api: openmp
    num_threads: 32
         prefix: libgomp
       filepath: <runtime-prefix>/lib/libgomp.so.1.0.0
        version: None

       user_api: blas
   internal_api: openblas
    num_threads: 32
         prefix: libscipy_openblas
       filepath: <runtime-prefix>/lib/python3.15/site-packages/scipy.libs/libscipy_openblas-b2dfe24b.so
        version: 0.3.34.0.0
threading_layer: pthreads
   architecture: SkylakeX

Interest in fixing the bug

No PR is being opened before triage.

Tool disclosure

The reporter supplied the Chinese statement above; Codex translated it. Codex (GPT-6 family; exact variant/effort unavailable) also prepared and executed the quoted diagnostic evidence and reproducer. No manual authorship, manual test execution, or manual code review of those artifacts is claimed for the reporter.

Activity

  1. added
    Needs Triage
    on Oct 18, 2026
  2. rudrasingh08182-dot commented on Oct 18, 2026

    @rudrasingh08182-dot

    Hi, I investigated this issue and implemented a potential fix for the IndexError that occurs when a feature contains only missing values.

    The change handles empty data after missing-value filtering in _find_binning_thresholds, and I added a regression test for an all-missing feature.

    Validation completed:

    • The binning test suite passes: 65 tests passed.
    • The public reproducer passes.
    • The sample-weight reproducer passes.

    I have not opened a pull request because the issue is currently awaiting triage. I would appreciate your feedback on whether this approach aligns with the project's expectations and whether a PR would be welcome.

    Thank you!

  3. cakedev0 commented on Oct 23, 2026

    @cakedev0
    Member

    This is a bug I introduced, I'll fix it.

  4. added and removed
    Needs Triage
    on Oct 23, 2026
  5. added a commit that references this issue on Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions