Skip to content

CI cp313t intermittent failure UserWarning: sklearn.utils.parallel.delayed should be used with sklearn.utils.parallel.Parallel #32631

Closed

Description

@lesteve

Also seen in #32303 (comment) as well in a different test and on Linux (this one is on macOS).

This is very likely related to warnings being thread-unsafe in cp313t. Not sure this is worth doing something about it since it doesn't seem to happen that often.

  ______________________ test_no_user_warning_with_scoring _______________________
  joblib.externals.loky.process_executor._RemoteTraceback: 
  """
  Traceback (most recent call last):
    File "/private/var/folders/q1/lmdr88vx1k90l53fxl9p8lwc0000gn/T/cibw-run-kd2mu_4k/cp313t-macosx_arm64/venv-test-arm64/lib/python3.13t/site-packages/joblib/_utils.py", line 72, in __call__
      return self.func(**kwargs)
             ~~~~~~~~~^^^^^^^^^^
    File "/private/var/folders/q1/lmdr88vx1k90l53fxl9p8lwc0000gn/T/cibw-run-kd2mu_4k/cp313t-macosx_arm64/venv-test-arm64/lib/python3.13t/site-packages/joblib/parallel.py", line 607, in __call__
      return [func(*args, **kwargs) for func, args, kwargs in self.items]
              ~~~~^^^^^^^^^^^^^^^^^
    File "/private/var/folders/q1/lmdr88vx1k90l53fxl9p8lwc0000gn/T/cibw-run-kd2mu_4k/cp313t-macosx_arm64/venv-test-arm64/lib/python3.13t/site-packages/sklearn/utils/parallel.py", line 144, in __call__
      warnings.warn(
      ~~~~~~~~~~~~~^
          (
          ^
      ...<5 lines>...
          UserWarning,
          ^^^^^^^^^^^^
      )
      ^
  UserWarning: `sklearn.utils.parallel.delayed` should be used with `sklearn.utils.parallel.Parallel` to make it possible to propagate the scikit-learn configuration of the current thread to the joblib workers.
  """
  
  The above exception was the direct cause of the following exception:
  
      def test_no_user_warning_with_scoring():
          """Check that no UserWarning is raised when scoring is set.
      
          Non-regression test for #22907.
          """
          pd = pytest.importorskip("pandas")
          X, y = make_regression(n_samples=50, random_state=0)
          X_df = pd.DataFrame(X, columns=[f"col{i}" for i in range(X.shape[1])])
      
          est = HistGradientBoostingRegressor(
              random_state=0, scoring="neg_mean_absolute_error", early_stopping=True
          )
          with warnings.catch_warnings():
              warnings.simplefilter("error", UserWarning)
  >           est.fit(X_df, y)
  
  ../venv-test-arm64/lib/python3.13t/site-packages/sklearn/ensemble/_hist_gradient_boosting/tests/test_gradient_boosting.py:1370: 
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
  ../venv-test-arm64/lib/python3.13t/site-packages/sklearn/base.py:1336: in wrapper
      return fit_method(estimator, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ../venv-test-arm64/lib/python3.13t/site-packages/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py:722: in fit
      X_binned_train = self._bin_data(X_train, is_training_data=True)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ../venv-test-arm64/lib/python3.13t/site-packages/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py:1237: in _bin_data
      X_binned = self._bin_mapper.fit_transform(X)  # F-aligned array
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ../venv-test-arm64/lib/python3.13t/site-packages/sklearn/utils/_set_output.py:316: in wrapped
      data_to_wrap = f(self, X, *args, **kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ../venv-test-arm64/lib/python3.13t/site-packages/sklearn/base.py:907: in fit_transform
      return self.fit(X, **fit_params).transform(X)
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  ../venv-test-arm64/lib/python3.13t/site-packages/sklearn/ensemble/_hist_gradient_boosting/binning.py:240: in fit
      non_cat_thresholds = Parallel(n_jobs=self.n_threads, backend="threading")(
  ../venv-test-arm64/lib/python3.13t/site-packages/sklearn/utils/parallel.py:91: in __call__
      return super().__call__(iterable_with_config_and_warning_filters)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ../venv-test-arm64/lib/python3.13t/site-packages/joblib/parallel.py:2072: in __call__
      return output if self.return_generator else list(output)
                                                  ^^^^^^^^^^^^
  ../venv-test-arm64/lib/python3.13t/site-packages/joblib/parallel.py:1682: in _get_outputs
      yield from self._retrieve()
  ../venv-test-arm64/lib/python3.13t/site-packages/joblib/parallel.py:1784: in _retrieve
      self._raise_error_fast()
  ../venv-test-arm64/lib/python3.13t/site-packages/joblib/parallel.py:1859: in _raise_error_fast
      error_job.get_result(self.timeout)
  ../venv-test-arm64/lib/python3.13t/site-packages/joblib/parallel.py:758: in get_result
      return self._return_or_raise()
             ^^^^^^^^^^^^^^^^^^^^^^^
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
  
  self = <joblib.parallel.BatchCompletionCallBack object at 0x5d4061e5010>
  
      def _return_or_raise(self):
          try:
              if self.status == TASK_ERROR:
  >               raise self._result
  E               UserWarning: `sklearn.utils.parallel.delayed` should be used with `sklearn.utils.parallel.Parallel` to make it possible to propagate the scikit-learn configuration of the current thread to the joblib workers.
  
  ../venv-test-arm64/lib/python3.13t/site-packages/joblib/parallel.py:773: UserWarning

Activity

  1. added
    Needs Triage
    on Nov 2, 2025
  2. changed the title [-]cp313t intermittent failure `UserWarning: `sklearn.utils.parallel.delayed` should be used with `sklearn.utils.parallel.Parallel``[/-] [+]cp313t intermittent failure `UserWarning: `sklearn.utils.parallel.delayed` should be used with `sklearn.utils.parallel.Parallel`[/+] on Nov 2, 2025
  3. changed the title [-]cp313t intermittent failure `UserWarning: `sklearn.utils.parallel.delayed` should be used with `sklearn.utils.parallel.Parallel`[/-] [+]cp313t intermittent failure `UserWarning: sklearn.utils.parallel.delayed should be used with sklearn.utils.parallel.Parallel`[/+] on Nov 2, 2025
  4. added and removed
    Needs Triage
    on Nov 2, 2025
  5. changed the title [-]cp313t intermittent failure `UserWarning: sklearn.utils.parallel.delayed should be used with sklearn.utils.parallel.Parallel`[/-] [+]CI cp313t intermittent failure `UserWarning: sklearn.utils.parallel.delayed should be used with sklearn.utils.parallel.Parallel`[/+] on Nov 2, 2025
  6. added
    free-threading
    on Nov 2, 2025
  7. lesteve commented on Feb 19, 2026

    @lesteve
    MemberAuthor

    I am not able to reproduce locally but since it adds some noise in the Wheels tracking issue #32393, I opened #33320 to xfail this test on Python 3.13 free-threaded.

  8. yangwao commented on Mar 5, 2026

    @yangwao

    Hey is this resolved? I came along had probably similar related error on p314 free threaded

    /home/node/.local/lib/python3.14/site-packages/sklearn/utils/parallel.py:144: UserWarning: `sklearn.utils.parallel.delayed` should be used with `sklearn.utils.parallel.Parallel` to make it possible to propagate the scikit-learn configuration of the current thread to the joblib workers.
      warnings.warn(

    Here what Claude Opus 4.6 thinks

    We're not directly using Parallel or delayed ourselves — this is coming from sklearn's internal usage. The warning fires when sklearn internally calls delayed()
    during model fitting (e.g., RandomForestClassifier, CalibratedClassifierCV, cross_val_score — all of which use parallel jobs internally).

    The issue is that sklearn's own code uses sklearn.utils.parallel.delayed but joblib's Parallel — it's a https://github.com/scikit-learn/scikit-learn/issues in
    certain versions. We can't fix it by changing our imports since we never call Parallel/delayed directly.

  9. pyrysepp commented on Sep 1, 2026

    @pyrysepp

    Hi! it appears to me that this hasn't been resolved so far. I can report the warning being annoying to deal with in a setup where a randomforestclassifier is used at scale. I managed to surpress the warnings by modifying the showwarning like so:

    ` original_showwarning = warnings.showwarning

    def filtered_showwarning(message, category, filename, lineno, file=None, line=None):
        if category is UserWarning and "sklearn.utils.parallel.delayed" in str(message):
            return
        original_showwarning(message, category, filename, lineno, file, line)
    
    warnings.showwarning = filtered_showwarning`
    
  10. lesteve commented on Sep 2, 2026

    @lesteve
    MemberAuthor

    This was an issue specific to Python 3.13t so please don't comment in this old closed issue.

    It is well possible that you get a similar warning for a different reason, if that's the case please open a separate issue with a reproducer 🙏. Without a reproducer there is not much we can do really.

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

    Build / CIfree-threading

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions