# Buggy code
def update_leaves_values(self, grower, y_true, raw_predictions, sample_weight):
    # Update the values predicted by the tree with
    # median(y_true - raw_predictions).
    # See note about need_update_leaves_values in BaseLoss.

    # TODO: ideally this should be computed in parallel over the leaves
    # using something similar to _update_raw_predictions(), but this
    # requires a cython version of median()
    for leaf in grower.finalized_leaves:
        indices = leaf.sample_indices
        if sample_weight is None:
            median_res = np.median(y_true[indices] - raw_predictions[indices])
        else:
            median_res = _weighted_percentile(
                y_true[indices] - raw_predictions[indices],
                sample_weight=sample_weight,
                percentile=50,
            )
        leaf.value = grower.shrinkage * median_res


# Traceback (ValueError)
Traceback (most recent call last):
File "/snap/pycharm-professional/230/plugins/python/helpers/pydev/pydevd.py", line 1477, in _exec
pydev_imports.execfile(file, globals, locals)  # execute the script
File "/snap/pycharm-professional/230/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/home/vadim/Загрузки/tt.py", line 11, in <module>
gb.fit(x, y, sample_weight=sample_weight)
File "/home/vadim/projects/monza/venv/lib/python3.8/site-packages/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py", line 466, in fit
self._loss.update_leaves_values(grower, y_train,
File "/home/vadim/projects/monza/venv/lib/python3.8/site-packages/sklearn/ensemble/_hist_gradient_boosting/loss.py", line 264, in update_leaves_values
median_res = _weighted_percentile(y_true[indices]
File "/home/vadim/projects/monza/venv/lib/python3.8/site-packages/sklearn/utils/stats.py", line 43, in _weighted_percentile
sorted_weights = _take_along_axis(sample_weight, sorted_idx, axis=0)
File "/home/vadim/projects/monza/venv/lib/python3.8/site-packages/sklearn/utils/fixes.py", line 172, in _take_along_axis
return np.take_along_axis(arr=arr, indices=indices, axis=axis)
File "<__array_function__ internals>", line 5, in take_along_axis
File "/home/vadim/projects/monza/venv/lib/python3.8/site-packages/numpy/lib/shape_base.py", line 170, in take_along_axis
return arr[_make_along_axis_idx(arr_shape, indices, axis)]
File "/home/vadim/projects/monza/venv/lib/python3.8/site-packages/numpy/lib/shape_base.py", line 34, in _make_along_axis_idx
raise ValueError(
ValueError: `indices` and `arr` must have the same number of dimensions

# Fixed code
def update_leaves_values(self, grower, y_true, raw_predictions, sample_weight):
    # Update the values predicted by the tree with
    # median(y_true - raw_predictions).
    # See note about need_update_leaves_values in BaseLoss.

    # TODO: ideally this should be computed in parallel over the leaves
    # using something similar to _update_raw_predictions(), but this
    # requires a cython version of median()
    for leaf in grower.finalized_leaves:
        indices = leaf.sample_indices
        if sample_weight is None:
            median_res = np.median(y_true[indices] - raw_predictions[indices])
        else:
            median_res = _weighted_percentile(
                y_true[indices] - raw_predictions[indices],
                sample_weight=sample_weight[indices],
                percentile=50,
            )
        leaf.value = grower.shrinkage * median_res